├── .gitignore ├── .vscode └── settings.json ├── LICENSE ├── Makefile ├── README.md ├── doc └── Doxyfile ├── lib ├── uthash.h └── utlist.h ├── src ├── api │ ├── elementnode.h │ ├── elements.c │ └── esstee.c ├── elements │ ├── array.c │ ├── array.h │ ├── block_header.c │ ├── block_header.h │ ├── builtins.c │ ├── builtins.h │ ├── date_time.c │ ├── date_time.h │ ├── derived.c │ ├── derived.h │ ├── directmemory.c │ ├── directmemory.h │ ├── enums.c │ ├── enums.h │ ├── iarray_index.h │ ├── idirectmemory.h │ ├── ifunction.h │ ├── ifunction_block.h │ ├── iinvoke_parameter.h │ ├── integers.c │ ├── integers.h │ ├── invoke_parameters.c │ ├── invoke_parameters.h │ ├── iprogram.h │ ├── iqualified_identifier.h │ ├── iqueries.h │ ├── itype.h │ ├── ivalue.h │ ├── ivariable.h │ ├── qualified_identifier.c │ ├── qualified_identifier.h │ ├── queries.c │ ├── queries.h │ ├── reals.c │ ├── reals.h │ ├── strings.c │ ├── strings.h │ ├── struct.c │ ├── struct.h │ ├── subrange.c │ ├── subrange.h │ ├── subrange_case.c │ ├── subrange_case.h │ ├── types.c │ ├── types.h │ ├── user_function_blocks.c │ ├── user_function_blocks.h │ ├── user_functions.c │ ├── user_functions.h │ ├── user_programs.c │ ├── user_programs.h │ ├── values.c │ ├── values.h │ ├── variable.c │ └── variable.h ├── esstee │ ├── elements.h │ ├── esstee.h │ ├── flags.h │ ├── issues.h │ └── locations.h ├── expressions │ ├── binary_expressions.c │ ├── binary_expressions.h │ ├── direct_address_term.c │ ├── direct_address_term.h │ ├── function_invocation.c │ ├── function_invocation.h │ ├── identifier.c │ ├── identifier.h │ ├── iexpression.h │ ├── inline_expression.c │ ├── inline_expression.h │ ├── negative_prefix.c │ ├── negative_prefix.h │ ├── qualified_identifier_term.c │ └── qualified_identifier_term.h ├── linker │ ├── linker.c │ └── linker.h ├── parser │ ├── bison.tab.h │ ├── bison.y │ ├── flex.h │ ├── flex.l │ ├── parray.c │ ├── parser.c │ ├── parser.h │ ├── pcases.c │ ├── pconditionals.c │ ├── pdirectmemory.c │ ├── penums.c │ ├── pexpressions.c │ ├── pheader.c │ ├── pinvokeparameters.c │ ├── pliterals.c │ ├── ppous.c │ ├── pqualified_identifier.c │ ├── pquery.c │ ├── pstatements.c │ ├── pstruct.c │ ├── psubrange.c │ ├── ptypes.c │ ├── pvalues.c │ ├── pvariables.c │ └── scanneroptions.h ├── rt │ ├── cursor.c │ ├── cursor.h │ ├── icursor.h │ ├── isystime.h │ ├── systime.c │ └── systime.h ├── statements │ ├── case.c │ ├── case.h │ ├── conditionals.c │ ├── conditionals.h │ ├── empty.c │ ├── empty.h │ ├── iinvoke.h │ ├── invoke_statement.c │ ├── invoke_statement.h │ ├── loops.c │ ├── loops.h │ ├── pop_call_stack.c │ ├── pop_call_stack.h │ ├── qualified_assignment.c │ ├── qualified_assignment.h │ ├── simple_assignment.c │ ├── simple_assignment.h │ ├── statements.c │ └── statements.h ├── tests │ ├── integration │ │ ├── README.md │ │ ├── arrays.tests │ │ ├── builtins.tests │ │ ├── conditionals.tests │ │ ├── derived_types.tests │ │ ├── direct_memory.tests │ │ ├── enum.tests │ │ ├── expressions.tests │ │ ├── function_blocks.tests │ │ ├── functions.tests │ │ ├── literals.tests │ │ ├── loops.tests │ │ ├── runtests.sh │ │ └── subrange.tests │ ├── program_tester │ │ └── main.c │ └── programs │ │ ├── arrays.ST │ │ ├── builtins │ │ └── cast.ST │ │ ├── conditionals.ST │ │ ├── derived_types │ │ ├── basic.ST │ │ └── circularrefs.ST │ │ ├── directmemory.ST │ │ ├── enum.ST │ │ ├── example.ST │ │ ├── function │ │ ├── badinput.ST │ │ ├── badinputname.ST │ │ ├── badnotin.ST │ │ ├── badtoomany.ST │ │ ├── disjointin.ST │ │ ├── funcparams.ST │ │ ├── min.ST │ │ ├── recursion.ST │ │ └── reset.ST │ │ ├── function_blocks │ │ ├── circular_ref.ST │ │ ├── circular_ref_2.ST │ │ ├── circular_ref_3.ST │ │ ├── circular_ref_4.ST │ │ ├── circular_ref_5.ST │ │ ├── circular_ref_6.ST │ │ ├── conditionals.ST │ │ ├── invoke.ST │ │ ├── loops.ST │ │ ├── noninput.ST │ │ ├── qualified_assignment.ST │ │ ├── simple.ST │ │ ├── simple_assignment.ST │ │ ├── toomany.ST │ │ └── undefined.ST │ │ ├── literals.ST │ │ ├── loops │ │ ├── for.ST │ │ ├── forexit.ST │ │ ├── forrange.ST │ │ ├── repeat.ST │ │ ├── repeatnotbool.ST │ │ ├── while.ST │ │ └── whilenotbool.ST │ │ └── subrange │ │ ├── badrange.ST │ │ └── basic.ST └── util │ ├── bitflag.h │ ├── config.c │ ├── config.h │ ├── iconfig.h │ ├── iissues.h │ ├── inamed_ref_pool.h │ ├── issue_context.c │ ├── issue_context.h │ ├── macros.h │ ├── named_ref_pool.c │ └── named_ref_pool.h └── utils ├── countlines.sh ├── todos-3.7.2016 ├── todos-5.1.2016 └── todos.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *~ 3 | *.h.gch 4 | src/tests/temp 5 | src/testground 6 | bison.output 7 | build 8 | trash 9 | src/tests/integration/error.output 10 | src/tests/integration/test.gdb.commands 11 | .cproject 12 | .emacs.desktop 13 | .emacs.desktop.lock 14 | .settings 15 | .project 16 | docker 17 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp.clang_format_fallbackStyle": "Google", 3 | "C_Cpp.clang_format_style": "Chromium" 4 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # esstee 2 | 3 | esstee is an interpreter written in C (GNU C99), currently under work, for the 4 | Structured Text (ST) programming language. Structured Text is one of the five 5 | languages defined in the IEC-61131-3 standard, and used a lot in the automation 6 | industry. 7 | 8 | The aim of esstee is to provide a, "free as in freedom", platform for building 9 | better testing and debug tools for ST applications. 10 | 11 | esstee is licensed under GPLv3. Besides Bison and Flex, esstee has no external 12 | dependencies besides the header libraries included in the source. Compiling has 13 | so far only been tested under Debian, but should work without problems in any 14 | Linux distro. 15 | 16 | ## Quick Start 17 | 18 | The first milestone of esstee is to provide a library that allows ST syntax to 19 | be parsed into a representation which can be stepped/run. The public interface 20 | to the library is defined in `src/esstee/esstee.h`. 21 | 22 | Currently, the parsing step of the library is complete (Flex and Bison grammar). 23 | In addition there is support for types (elementary, derived and complex), all 24 | statements and expressions, however it is not yet properly tested (automatic 25 | integration tests not ready), and should be considered as **under work**. 26 | 27 | A simple test program using the library interface (and building all the current 28 | code) can be built by; 29 | 30 | ``` 31 | make build/program-tester 32 | ``` 33 | 34 | The program parses ST syntax from a file, then executes possible "pre" queries 35 | on the runnable representation, runs N cycles and finally executes possible 36 | "post" queries. A query is either a variable reference or an assignment. The 37 | program takes the following options: 38 | 39 | - **file** the file to parse 40 | - **program** the `PROGRAM` in the file that is to be run (a file may contain multiple programs) 41 | - **pre-run-queries** the queries to run right after parsing 42 | - **run-cycles** number of cycles to run (default 1) 43 | - **post-run-queries** the queries to run after the cycles have been run 44 | 45 | In pre and post queries, access the program variables by prefixing with `[name-of-program]`. 46 | 47 | An example: 48 | 49 | ``` 50 | ./build/program-tester --file="src/tests/programs/example.ST" --program="testprgm" --pre-run-queries="[testprgm].a:=10*5+1" --post-run-queries="[testprgm].a" 51 | 52 | ``` 53 | -------------------------------------------------------------------------------- /src/api/elementnode.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | struct element_node_context_t { 29 | struct issues_iface_t *issues; 30 | const struct config_iface_t *config; 31 | }; 32 | 33 | struct element_node_t { 34 | struct st_element_t element; 35 | const struct element_node_context_t *context; 36 | struct value_iface_t *value; 37 | 38 | struct element_node_t *sub_nodes; 39 | 40 | char *identifier; 41 | UT_hash_handle hh; 42 | }; 43 | 44 | struct element_node_t * st_new_element_node( 45 | const char *identifier, 46 | struct value_iface_t *value, 47 | const struct element_node_context_t *context); 48 | -------------------------------------------------------------------------------- /src/elements/array.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | 29 | struct array_range_iface_t { 30 | 31 | int (*extend)( 32 | struct array_range_iface_t *self, 33 | struct subrange_iface_t *subrange, 34 | const struct config_iface_t *config, 35 | struct issues_iface_t *issues); 36 | 37 | void (*destroy)( 38 | struct array_range_iface_t *self); 39 | }; 40 | 41 | struct array_initializer_iface_t { 42 | 43 | int (*extend_by_value)( 44 | struct array_initializer_iface_t *self, 45 | struct value_iface_t *value, 46 | const struct st_location_t *value_location, 47 | const struct config_iface_t *config, 48 | struct issues_iface_t *issues); 49 | 50 | int (*extend_by_multiplied_value)( 51 | struct array_initializer_iface_t *self, 52 | struct value_iface_t *multiplier, 53 | struct value_iface_t *value, 54 | const struct st_location_t *location, 55 | const struct config_iface_t *config, 56 | struct issues_iface_t *issues); 57 | 58 | struct value_iface_t * (*value)( 59 | struct array_initializer_iface_t *self); 60 | 61 | void (*destroy)( 62 | struct array_initializer_iface_t *self); 63 | }; 64 | 65 | struct array_index_iface_t * st_create_array_index( 66 | const struct config_iface_t *config, 67 | struct issues_iface_t *issues); 68 | 69 | struct array_range_iface_t * st_create_array_range( 70 | const struct config_iface_t *config, 71 | struct issues_iface_t *issues); 72 | 73 | struct array_initializer_iface_t * st_create_array_initializer( 74 | const struct config_iface_t *config, 75 | struct issues_iface_t *issues); 76 | 77 | struct type_iface_t * st_create_array_type( 78 | struct array_range_iface_t *array_range, 79 | char *arrayed_type_identifier, 80 | const struct st_location_t *arrayed_type_identifier_location, 81 | struct value_iface_t *default_value, 82 | const struct st_location_t *default_value_location, 83 | struct named_ref_pool_iface_t *type_refs, 84 | const struct config_iface_t *config, 85 | struct issues_iface_t *issues); 86 | -------------------------------------------------------------------------------- /src/elements/block_header.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | 24 | int st_create_header_tables( 25 | struct header_t *header, 26 | struct issues_iface_t *issues) 27 | { 28 | if(!header) 29 | { 30 | return ESSTEE_OK; 31 | } 32 | 33 | int result = ESSTEE_OK; 34 | 35 | /* Make hash table from type list */ 36 | int issues_at_type_start = issues->count(issues, ESSTEE_FILTER_ANY_ERROR); 37 | struct type_iface_t *type_table = 38 | st_link_types(header->types, NULL, issues); 39 | 40 | if(issues->count(issues, ESSTEE_FILTER_ANY_ERROR) == issues_at_type_start) 41 | { 42 | header->types = type_table; 43 | } 44 | else 45 | { 46 | result = ESSTEE_ERROR; 47 | } 48 | 49 | /* Make hash table from var list */ 50 | int issues_at_var_start = issues->count(issues, ESSTEE_FILTER_ANY_ERROR); 51 | struct variable_iface_t *variable_table 52 | = st_link_variables(header->variables, NULL, issues); 53 | 54 | if(issues->count(issues, ESSTEE_FILTER_ANY_ERROR) == issues_at_var_start) 55 | { 56 | header->variables = variable_table; 57 | } 58 | else 59 | { 60 | result = ESSTEE_ERROR; 61 | } 62 | 63 | return result; 64 | } 65 | 66 | void st_destroy_header( 67 | struct header_t *header) 68 | { 69 | /* TODO: destroy block header */ 70 | } 71 | -------------------------------------------------------------------------------- /src/elements/block_header.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | struct header_t { 26 | struct type_iface_t *types; 27 | struct variable_iface_t *variables; 28 | }; 29 | 30 | int st_create_header_tables( 31 | struct header_t *header, 32 | struct issues_iface_t *issues); 33 | 34 | void st_destroy_header( 35 | struct header_t *header); 36 | -------------------------------------------------------------------------------- /src/elements/builtins.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | struct function_iface_t * st_new_builtin_functions( 26 | struct type_iface_t *builtin_types 27 | ); 28 | 29 | struct function_block_iface_t * st_new_builtin_function_blocks( 30 | struct type_iface_t *builtin_types 31 | ); 32 | -------------------------------------------------------------------------------- /src/elements/date_time.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | #include 25 | 26 | struct duration_t { 27 | double d; 28 | double h; 29 | double m; 30 | double s; 31 | double ms; 32 | }; 33 | 34 | struct date_t { 35 | uint64_t y; 36 | uint8_t m; 37 | uint8_t d; 38 | }; 39 | 40 | struct tod_t { 41 | uint8_t h; 42 | uint8_t m; 43 | uint8_t s; 44 | uint8_t fs; 45 | }; 46 | 47 | struct date_tod_t { 48 | struct date_t date; 49 | struct tod_t tod; 50 | }; 51 | 52 | struct type_iface_t * st_new_elementary_date_time_types(); 53 | 54 | struct value_iface_t * st_new_typeless_duration_value( 55 | double days, 56 | double hours, 57 | double minutes, 58 | double seconds, 59 | double milliseconds, 60 | st_bitflag_t value_class, 61 | const struct config_iface_t *config, 62 | struct issues_iface_t *issues); 63 | 64 | struct value_iface_t * st_new_typeless_date_value( 65 | uint64_t year, 66 | uint8_t month, 67 | uint8_t day, 68 | st_bitflag_t value_class, 69 | const struct config_iface_t *config, 70 | struct issues_iface_t *issues); 71 | 72 | struct value_iface_t * st_new_typeless_tod_value( 73 | uint8_t hour, 74 | uint8_t minute, 75 | uint8_t second, 76 | uint8_t partial_second, 77 | st_bitflag_t value_class, 78 | const struct config_iface_t *config, 79 | struct issues_iface_t *issues); 80 | 81 | struct value_iface_t * st_new_typeless_date_tod_value( 82 | uint64_t year, 83 | uint8_t month, 84 | uint8_t day, 85 | uint8_t hour, 86 | uint8_t minute, 87 | uint8_t second, 88 | uint8_t partial_second, 89 | st_bitflag_t value_class, 90 | const struct config_iface_t *config, 91 | struct issues_iface_t *issues); 92 | 93 | -------------------------------------------------------------------------------- /src/elements/derived.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | struct type_iface_t * st_create_derived_type( 26 | char *type_name, 27 | struct type_iface_t *parent_type, 28 | const struct st_location_t *location, 29 | struct value_iface_t *default_value, 30 | const struct st_location_t *default_value_location, 31 | struct named_ref_pool_iface_t *type_refs, 32 | const struct config_iface_t *config, 33 | struct issues_iface_t *issues); 34 | 35 | struct type_iface_t * st_create_derived_type_by_name( 36 | char *type_name, 37 | const struct st_location_t *location, 38 | char *parent_type_name, 39 | const struct st_location_t *parent_type_name_location, 40 | struct value_iface_t *default_value, 41 | const struct st_location_t *default_value_location, 42 | struct named_ref_pool_iface_t *type_refs, 43 | const struct config_iface_t *config, 44 | struct issues_iface_t *issues); 45 | -------------------------------------------------------------------------------- /src/elements/directmemory.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | struct direct_memory_t { 26 | struct dmem_iface_t dmem; 27 | uint8_t *storage; 28 | size_t size; 29 | }; 30 | 31 | static uint8_t * direct_memory_offset( 32 | struct dmem_iface_t *self, 33 | const struct direct_address_t *address, 34 | const struct config_iface_t *config, 35 | struct issues_iface_t *issues) 36 | { 37 | struct direct_memory_t *dm = 38 | CONTAINER_OF(self, struct direct_memory_t, dmem); 39 | 40 | if(address->byte_offset >= dm->size) 41 | { 42 | issues->new_issue(issues, 43 | "byte offset '%lu' fall outside the direct memory area of '%lu' bytes", 44 | ESSTEE_CONTEXT_ERROR, 45 | address->byte_offset, 46 | dm->size); 47 | return NULL; 48 | } 49 | 50 | size_t extra_byte_offset = address->bit_offset / 8; 51 | if(address->byte_offset + extra_byte_offset >= dm->size) 52 | { 53 | issues->new_issue(issues, 54 | "bit offset '%lu' makes the byte offset fall outside the direct memory area of '%lu' bytes", 55 | ESSTEE_CONTEXT_ERROR, 56 | address->bit_offset, 57 | dm->size); 58 | return NULL; 59 | } 60 | 61 | size_t offset_last_byte = address->byte_offset 62 | + extra_byte_offset 63 | + address->field_size_bits / 8; 64 | 65 | if(offset_last_byte > dm->size) 66 | { 67 | issues->new_issue(issues, 68 | "field of size '%lu' at offset '%lu' would extend outside the direct memory area of '%lu' bytes", 69 | ESSTEE_CONTEXT_ERROR, 70 | address->field_size_bits, 71 | address->byte_offset, 72 | dm->size); 73 | return NULL; 74 | } 75 | 76 | return dm->storage + address->byte_offset + extra_byte_offset; 77 | } 78 | 79 | static int direct_memory_reset( 80 | struct dmem_iface_t *self) 81 | { 82 | return ESSTEE_ERROR; 83 | } 84 | 85 | static void direct_memory_destroy( 86 | struct dmem_iface_t *self) 87 | { 88 | /* TODO: direct memory destructor */ 89 | } 90 | 91 | struct dmem_iface_t * st_new_direct_memory( 92 | size_t direct_memory_bytes) 93 | { 94 | struct direct_memory_t *dm = NULL; 95 | uint8_t *storage = NULL; 96 | 97 | ALLOC_OR_JUMP( 98 | dm, 99 | struct direct_memory_t, 100 | error_free_resources); 101 | 102 | ALLOC_ARRAY_OR_JUMP( 103 | storage, 104 | uint8_t, 105 | direct_memory_bytes, 106 | error_free_resources); 107 | 108 | dm->storage = storage; 109 | dm->size = direct_memory_bytes; 110 | memset(dm->storage, 0, dm->size); 111 | 112 | dm->dmem.offset = direct_memory_offset; 113 | dm->dmem.reset = direct_memory_reset; 114 | dm->dmem.destroy = direct_memory_destroy; 115 | 116 | return &(dm->dmem); 117 | 118 | error_free_resources: 119 | free(dm); 120 | free(storage); 121 | return NULL; 122 | } 123 | -------------------------------------------------------------------------------- /src/elements/directmemory.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | struct dmem_iface_t * st_new_direct_memory( 26 | size_t direct_memory_bytes); 27 | 28 | -------------------------------------------------------------------------------- /src/elements/enums.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | struct enum_item_t { 25 | const char *identifier; 26 | const struct st_location_t *location; 27 | }; 28 | 29 | struct enum_group_iface_t { 30 | 31 | int (*extend)( 32 | struct enum_group_iface_t *self, 33 | char *identifier, 34 | const struct st_location_t *location, 35 | const struct config_iface_t *config, 36 | struct issues_iface_t *issues); 37 | 38 | void (*destroy)( 39 | struct enum_group_iface_t *self); 40 | }; 41 | 42 | struct enum_group_iface_t * st_create_enum_group( 43 | const struct config_iface_t *config, 44 | struct issues_iface_t *issues); 45 | 46 | struct type_iface_t * st_create_enum_type( 47 | struct enum_group_iface_t *group, 48 | const char *default_item, 49 | const struct st_location_t *default_item_location, 50 | const struct config_iface_t *config, 51 | struct issues_iface_t *issues); 52 | 53 | struct value_iface_t * st_create_enum_value( 54 | char *identifier, 55 | const struct st_location_t *location, 56 | const struct config_iface_t *config, 57 | struct issues_iface_t *issues); 58 | -------------------------------------------------------------------------------- /src/elements/iarray_index.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | struct array_index_element_t { 29 | const struct expression_iface_t *expression; 30 | const struct array_index_element_t *next; 31 | }; 32 | 33 | struct array_index_iface_t { 34 | 35 | int (*step)( 36 | struct array_index_iface_t *self, 37 | struct cursor_iface_t *cursor, 38 | const struct systime_iface_t *time, 39 | const struct config_iface_t *config, 40 | struct issues_iface_t *issues); 41 | 42 | int (*reset)( 43 | struct array_index_iface_t *self, 44 | const struct config_iface_t *config, 45 | struct issues_iface_t *issues); 46 | 47 | int (*allocate)( 48 | struct array_index_iface_t *self, 49 | struct issues_iface_t *issues); 50 | 51 | struct array_index_iface_t * (*clone)( 52 | struct array_index_iface_t *self, 53 | struct issues_iface_t *issues); 54 | 55 | int (*extend)( 56 | struct array_index_iface_t *self, 57 | struct expression_iface_t *expression, 58 | const struct st_location_t *expression_location, 59 | const struct config_iface_t *config, 60 | struct issues_iface_t *issues); 61 | 62 | int (*constant_reference)( 63 | struct array_index_iface_t *self); 64 | 65 | void (*destroy)( 66 | struct array_index_iface_t *self); 67 | 68 | const struct array_index_element_t *first_node; 69 | const struct st_location_t *location; 70 | }; 71 | -------------------------------------------------------------------------------- /src/elements/idirectmemory.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #define MEMORY_DIRECT_ADDRESS (1 << 0) 23 | #define INPUT_DIRECT_ADDRESS (1 << 1) 24 | #define OUTPUT_DIRECT_ADDRESS (1 << 2) 25 | #define BIT_UNIT_ADDRESS (1 << 3) 26 | #define BYTE_UNIT_ADDRESS (1 << 4) 27 | #define WORD_UNIT_ADDRESS (1 << 5) 28 | #define DWORD_UNIT_ADDRESS (1 << 6) 29 | #define LONG_UNIT_ADDRESS (1 << 7) 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | struct direct_address_t { 39 | st_bitflag_t class; 40 | size_t byte_offset; 41 | size_t bit_offset; 42 | size_t field_size_bits; 43 | uint8_t *storage; 44 | }; 45 | 46 | struct dmem_iface_t { 47 | 48 | uint8_t * (*offset)( 49 | struct dmem_iface_t *self, 50 | const struct direct_address_t *da, 51 | const struct config_iface_t *config, 52 | struct issues_iface_t *issues); 53 | 54 | int (*reset)( 55 | struct dmem_iface_t *self); 56 | 57 | void (*destroy)( 58 | struct dmem_iface_t *self); 59 | }; 60 | -------------------------------------------------------------------------------- /src/elements/ifunction.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | struct function_iface_t { 33 | 34 | int (*finalize_header)( 35 | struct function_iface_t *self, 36 | struct type_iface_t *global_type_table, 37 | struct variable_iface_t *global_var_table, 38 | const struct config_iface_t *config, 39 | struct issues_iface_t *issues); 40 | 41 | int (*finalize_statements)( 42 | struct function_iface_t *self, 43 | const struct config_iface_t *config, 44 | struct issues_iface_t *issues); 45 | 46 | int (*verify_invoke)( 47 | struct function_iface_t *self, 48 | struct invoke_parameters_iface_t *parameters, 49 | const struct config_iface_t *config, 50 | struct issues_iface_t *issues); 51 | 52 | int (*step)( 53 | struct function_iface_t *self, 54 | struct invoke_parameters_iface_t *parameters, 55 | struct cursor_iface_t *cursor, 56 | const struct systime_iface_t *time, 57 | const struct config_iface_t *config, 58 | struct issues_iface_t *issues); 59 | 60 | int (*reset)( 61 | struct function_iface_t *self, 62 | const struct config_iface_t *config, 63 | struct issues_iface_t *issues); 64 | 65 | const struct value_iface_t * (*result_value)( 66 | struct function_iface_t *self); 67 | 68 | void (*destroy)( 69 | struct function_iface_t *self); 70 | 71 | const char *identifier; 72 | const struct st_location_t *location; 73 | struct function_iface_t *prev; 74 | struct function_iface_t *next; 75 | UT_hash_handle hh; 76 | }; 77 | -------------------------------------------------------------------------------- /src/elements/ifunction_block.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | struct function_block_iface_t { 31 | 32 | int (*resolve_header_type_references)( 33 | struct function_block_iface_t *self, 34 | struct type_iface_t *global_type_table, 35 | const struct config_iface_t *config, 36 | struct issues_iface_t *issues); 37 | 38 | int (*check_dependencies)( 39 | struct function_block_iface_t *self, 40 | const struct config_iface_t *config, 41 | struct issues_iface_t *issues); 42 | 43 | int (*finalize_header)( 44 | struct function_block_iface_t *self, 45 | struct variable_iface_t *global_var_table, 46 | const struct config_iface_t *config, 47 | struct issues_iface_t *issues); 48 | 49 | int (*finalize_statements)( 50 | struct function_block_iface_t *self, 51 | const struct config_iface_t *config, 52 | struct issues_iface_t *issues); 53 | 54 | void (*destroy)( 55 | struct function_block_iface_t *self); 56 | 57 | const char *identifier; 58 | const struct st_location_t *location; 59 | struct function_block_iface_t *prev; 60 | struct function_block_iface_t *next; 61 | UT_hash_handle hh; 62 | }; 63 | -------------------------------------------------------------------------------- /src/elements/iinvoke_parameter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | struct invoke_parameter_t; 28 | 29 | struct invoke_parameters_iface_t { 30 | 31 | int (*append)( 32 | struct invoke_parameters_iface_t *self, 33 | struct invoke_parameter_t *parameter, 34 | const struct config_iface_t *config, 35 | struct issues_iface_t *issues); 36 | 37 | int (*verify)( 38 | const struct invoke_parameters_iface_t *self, 39 | const struct variable_iface_t *variables, 40 | const struct config_iface_t *config, 41 | struct issues_iface_t *issues); 42 | 43 | int (*step)( 44 | struct invoke_parameters_iface_t *self, 45 | struct cursor_iface_t *cursor, 46 | const struct systime_iface_t *time, 47 | const struct config_iface_t *config, 48 | struct issues_iface_t *issues); 49 | 50 | int (*reset)( 51 | struct invoke_parameters_iface_t *self, 52 | const struct config_iface_t *config, 53 | struct issues_iface_t *issues); 54 | 55 | int (*allocate)( 56 | struct invoke_parameters_iface_t *self, 57 | struct issues_iface_t *issues); 58 | 59 | struct invoke_parameters_iface_t * (*clone)( 60 | struct invoke_parameters_iface_t *self, 61 | struct issues_iface_t *issues); 62 | 63 | int (*assign_from)( 64 | const struct invoke_parameters_iface_t *self, 65 | struct variable_iface_t *variables, 66 | const struct config_iface_t *config, 67 | struct issues_iface_t *issues); 68 | 69 | void (*destroy)( 70 | struct invoke_parameters_iface_t *self); 71 | 72 | }; 73 | -------------------------------------------------------------------------------- /src/elements/integers.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | struct type_iface_t * st_new_elementary_integer_types(); 25 | 26 | struct value_iface_t * st_new_typeless_integer_value( 27 | int64_t num, 28 | st_bitflag_t value_class, 29 | const struct config_iface_t *config, 30 | struct issues_iface_t *issues); 31 | 32 | int st_integer_value_set( 33 | struct value_iface_t *value, 34 | int64_t num); 35 | 36 | struct value_iface_t * st_new_bool_value( 37 | int state, 38 | st_bitflag_t value_class, 39 | const struct config_iface_t *config, 40 | struct issues_iface_t *issues); 41 | 42 | int st_set_bool_value_state( 43 | struct value_iface_t *value, 44 | int state); 45 | -------------------------------------------------------------------------------- /src/elements/invoke_parameters.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | struct invoke_parameters_iface_t * st_create_invoke_parameters( 24 | struct invoke_parameter_t *first_parameter, 25 | const struct config_iface_t *config, 26 | struct issues_iface_t *issues); 27 | 28 | struct invoke_parameter_t * st_create_invoke_parameter( 29 | char *identifier, 30 | const struct st_location_t *location, 31 | struct expression_iface_t *assigned, 32 | const struct config_iface_t *config, 33 | struct issues_iface_t *issues); 34 | 35 | void st_destroy_invoke_parameter( 36 | struct invoke_parameter_t *parameter); 37 | -------------------------------------------------------------------------------- /src/elements/iprogram.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | n 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | struct program_iface_t { 30 | 31 | int (*finalize_header)( 32 | struct program_iface_t *self, 33 | struct type_iface_t *global_type_table, 34 | struct variable_iface_t *global_var_table, 35 | const struct config_iface_t *config, 36 | struct issues_iface_t *issues); 37 | 38 | int (*finalize_statements)( 39 | struct program_iface_t *self, 40 | const struct config_iface_t *config, 41 | struct issues_iface_t *issues); 42 | 43 | int (*start)( 44 | struct program_iface_t *self, 45 | struct cursor_iface_t *cursor, 46 | const struct config_iface_t *config, 47 | struct issues_iface_t *issues); 48 | 49 | int (*run_cycle)( 50 | struct program_iface_t *self, 51 | struct cursor_iface_t *cursor, 52 | struct systime_iface_t *systime, 53 | const struct config_iface_t *config, 54 | struct issues_iface_t *issues); 55 | 56 | struct variable_iface_t * (*variable)( 57 | struct program_iface_t *self, 58 | const char *variable_identifier, 59 | const struct config_iface_t *config, 60 | struct issues_iface_t *issues); 61 | 62 | int (*display)( 63 | struct program_iface_t *self, 64 | char *buffer, 65 | size_t buffer_size, 66 | const struct config_iface_t *config); 67 | 68 | void (*destroy)( 69 | struct program_iface_t *self); 70 | 71 | const char *identifier; 72 | const struct st_location_t *location; 73 | struct program_iface_t *prev; 74 | struct program_iface_t *next; 75 | UT_hash_handle hh; 76 | }; 77 | -------------------------------------------------------------------------------- /src/elements/iqueries.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | struct query_t; 30 | 31 | struct queries_iface_t { 32 | 33 | int (*append)( 34 | struct queries_iface_t *self, 35 | struct query_t *query, 36 | const struct config_iface_t *config, 37 | struct issues_iface_t *issues); 38 | 39 | int (*finish)( 40 | struct queries_iface_t *self, 41 | struct named_ref_pool_iface_t *var_refs, 42 | struct named_ref_pool_iface_t *function_refs, 43 | struct named_ref_pool_iface_t *program_refs, 44 | const struct config_iface_t *config, 45 | struct issues_iface_t *issues); 46 | 47 | int (*link)( 48 | struct queries_iface_t *self, 49 | struct variable_iface_t *global_variables, 50 | struct function_iface_t *functions, 51 | struct program_iface_t *programs, 52 | const struct config_iface_t *config, 53 | struct issues_iface_t *issues); 54 | 55 | int (*evaluate)( 56 | struct queries_iface_t *self, 57 | const struct config_iface_t *config, 58 | struct issues_iface_t *issues); 59 | 60 | int (*display)( 61 | struct queries_iface_t *self, 62 | char *output, 63 | size_t output_max_len, 64 | const struct config_iface_t *config, 65 | struct issues_iface_t *issues); 66 | 67 | void (*destroy)( 68 | struct queries_iface_t *self); 69 | 70 | }; 71 | -------------------------------------------------------------------------------- /src/elements/itype.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #define INTEGER_NUMERIC_CLASS (1 << 0) 31 | #define INTEGER_BITDATA_CLASS (1 << 1) 32 | #define REAL_NUMERIC_CLASS (1 << 2) 33 | #define INTEGER_SIGNED (1 << 3) 34 | #define INTEGER_UNSIGNED (1 << 4) 35 | #define INTEGER_BOOL_TYPE (1 << 5) 36 | #define INTEGER_SINT_TYPE (1 << 6) 37 | #define INTEGER_INT_TYPE (1 << 7) 38 | #define INTEGER_DINT_TYPE (1 << 8) 39 | #define INTEGER_LINT_TYPE (1 << 9) 40 | #define INTEGER_USINT_TYPE (1 << 10) 41 | #define INTEGER_UINT_TYPE (1 << 11) 42 | #define INTEGER_UDINT_TYPE (1 << 12) 43 | #define INTEGER_ULINT_TYPE (1 << 13) 44 | #define INTEGER_BYTE_TYPE (1 << 14) 45 | #define INTEGER_WORD_TYPE (1 << 15) 46 | #define INTEGER_DWORD_TYPE (1 << 16) 47 | #define INTEGER_LWORD_TYPE (1 << 17) 48 | #define REAL_TYPE (1 << 18) 49 | #define LREAL_TYPE (1 << 19) 50 | #define STRING_TYPE (1 << 20) 51 | #define WSTRING_TYPE (1 << 21) 52 | #define DURATION_TYPE (1 << 22) 53 | #define DATE_TYPE (1 << 23) 54 | #define TOD_TYPE (1 << 24) 55 | #define DATE_TOD_TYPE (1 << 25) 56 | #define DERIVED_TYPE (1 << 26) 57 | #define ENUM_TYPE (1 << 27) 58 | #define SUBRANGE_TYPE (1 << 28) 59 | #define ARRAY_TYPE (1 << 29) 60 | #define STRUCT_TYPE (1 << 30) 61 | #define FB_TYPE (1 << 31) 62 | 63 | struct type_iface_t { 64 | 65 | struct value_iface_t * (*create_value_of)( 66 | const struct type_iface_t *self, 67 | const struct config_iface_t *config, 68 | struct issues_iface_t *issues); 69 | 70 | int (*reset_value_of)( 71 | const struct type_iface_t *self, 72 | struct value_iface_t *value_of, 73 | const struct config_iface_t *config, 74 | struct issues_iface_t *issues); 75 | 76 | int (*cast_value_of)( 77 | const struct type_iface_t *self, 78 | struct value_iface_t *value_of, 79 | const struct value_iface_t *cast_value, 80 | const struct config_iface_t *config, 81 | struct issues_iface_t *issues); 82 | 83 | void (*sync_direct_memory)( 84 | const struct type_iface_t *self, 85 | struct value_iface_t *value_of, 86 | const struct direct_address_t *address, 87 | int write); 88 | 89 | int (*validate_direct_address)( 90 | const struct type_iface_t *self, 91 | struct direct_address_t *address, 92 | struct issues_iface_t *issues); 93 | 94 | int (*can_hold)( 95 | const struct type_iface_t *self, 96 | const struct value_iface_t *value, 97 | const struct config_iface_t *config, 98 | struct issues_iface_t *issues); 99 | 100 | int (*compatible)( 101 | const struct type_iface_t *self, 102 | const struct type_iface_t *other_type, 103 | const struct config_iface_t *config, 104 | struct issues_iface_t *issues); 105 | 106 | const struct type_iface_t * (*ancestor)( 107 | const struct type_iface_t *self); 108 | 109 | const struct function_block_iface_t * (*const_function_block_handle)( 110 | const struct type_iface_t *self); 111 | 112 | struct function_block_iface_t * (*function_block_handle)( 113 | struct type_iface_t *self); 114 | 115 | st_bitflag_t (*class)( 116 | const struct type_iface_t *self); 117 | 118 | void (*destroy)( 119 | struct type_iface_t *self); 120 | 121 | const char *identifier; 122 | const struct st_location_t *location; 123 | UT_hash_handle hh; 124 | struct type_iface_t *prev; 125 | struct type_iface_t *next; 126 | }; 127 | -------------------------------------------------------------------------------- /src/elements/qualified_identifier.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | struct qualified_identifier_iface_t * st_create_qualified_identifier( 26 | struct named_ref_pool_iface_t *variable_context, 27 | const struct config_iface_t *config, 28 | struct issues_iface_t *issues); 29 | -------------------------------------------------------------------------------- /src/elements/queries.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | struct query_t * st_create_program_query( 28 | char *prgm_identifier, 29 | const struct st_location_t *prgm_identifier_location, 30 | struct named_ref_pool_iface_t *program_refs, 31 | const struct config_iface_t *config, 32 | struct issues_iface_t *issues); 33 | 34 | struct query_t * st_create_identifier_query( 35 | char *prgm_identifier, 36 | const struct st_location_t *prgm_location, 37 | char *identifier, 38 | const struct st_location_t *identifier_location, 39 | struct expression_iface_t *assigned, 40 | struct named_ref_pool_iface_t *program_refs, 41 | struct named_ref_pool_iface_t *var_refs, 42 | const struct config_iface_t *config, 43 | struct issues_iface_t *issues); 44 | 45 | struct query_t * st_create_qualified_identifier_query( 46 | char *prgm_identifier, 47 | const struct st_location_t *prgm_location, 48 | struct qualified_identifier_iface_t *qid, 49 | struct expression_iface_t *assigned, 50 | struct named_ref_pool_iface_t *program_refs, 51 | const struct config_iface_t *config, 52 | struct issues_iface_t *issues); 53 | 54 | void st_destroy_query( 55 | struct query_t *query); 56 | 57 | struct queries_iface_t * st_create_queries( 58 | struct query_t *first_query, 59 | const struct config_iface_t *config, 60 | struct issues_iface_t *issues); 61 | -------------------------------------------------------------------------------- /src/elements/reals.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | struct type_iface_t * st_new_elementary_real_types(); 25 | 26 | struct value_iface_t * st_new_typeless_real_value( 27 | double num, 28 | st_bitflag_t value_class, 29 | const struct config_iface_t *config, 30 | struct issues_iface_t *issues); 31 | -------------------------------------------------------------------------------- /src/elements/strings.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | struct type_iface_t * st_new_elementary_string_types(); 26 | 27 | struct type_iface_t * st_new_custom_length_string_type( 28 | const char *type_name, 29 | struct value_iface_t *length, 30 | const struct st_location_t *length_location, 31 | struct value_iface_t *default_value, 32 | const struct config_iface_t *config, 33 | struct issues_iface_t *issues); 34 | 35 | struct value_iface_t * st_new_string_value( 36 | const char *type_name, 37 | char *content, 38 | const struct config_iface_t *config, 39 | struct issues_iface_t *issues); 40 | -------------------------------------------------------------------------------- /src/elements/struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | struct struct_elements_iface_t { 26 | 27 | int (*extend_by_type)( 28 | struct struct_elements_iface_t *self, 29 | char *identifier, 30 | const struct st_location_t *identifier_location, 31 | struct type_iface_t *type, 32 | const struct config_iface_t *config, 33 | struct issues_iface_t *issues); 34 | 35 | int (*extend_by_type_name)( 36 | struct struct_elements_iface_t *self, 37 | char *identifier, 38 | const struct st_location_t *identifier_location, 39 | char *type_name, 40 | const struct st_location_t *type_name_location, 41 | struct named_ref_pool_iface_t *type_refs, 42 | const struct config_iface_t *config, 43 | struct issues_iface_t *issues); 44 | 45 | void (*destroy)( 46 | struct struct_elements_iface_t *self); 47 | }; 48 | 49 | struct struct_initializer_iface_t { 50 | 51 | int (*extend)( 52 | struct struct_initializer_iface_t *self, 53 | char *identifier, 54 | const struct st_location_t *identifier_location, 55 | struct value_iface_t *value, 56 | const struct config_iface_t *config, 57 | struct issues_iface_t *issues); 58 | 59 | struct value_iface_t * (*value)( 60 | struct struct_initializer_iface_t *self); 61 | 62 | void (*destroy)( 63 | struct struct_initializer_iface_t *self); 64 | 65 | const struct st_location_t *location; 66 | }; 67 | 68 | struct struct_elements_iface_t * st_create_struct_elements( 69 | const struct config_iface_t *config, 70 | struct issues_iface_t *issues); 71 | 72 | struct struct_initializer_iface_t * st_create_struct_initializer( 73 | const struct config_iface_t *config, 74 | struct issues_iface_t *issues); 75 | 76 | struct type_iface_t * st_create_struct_type( 77 | struct struct_elements_iface_t *elements, 78 | const struct config_iface_t *config, 79 | struct issues_iface_t *issues); 80 | -------------------------------------------------------------------------------- /src/elements/subrange.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | struct subrange_iface_t { 26 | 27 | void (*destroy)( 28 | struct subrange_iface_t *self); 29 | 30 | const struct value_iface_t *min; 31 | const struct st_location_t *min_location; 32 | const struct value_iface_t *max; 33 | const struct st_location_t *max_location; 34 | const struct st_location_t *location; 35 | }; 36 | 37 | struct subrange_iface_t * st_create_subrange( 38 | struct value_iface_t *min, 39 | const struct st_location_t *min_location, 40 | struct value_iface_t *max, 41 | const struct st_location_t *max_location, 42 | const struct st_location_t *location, 43 | const struct config_iface_t *config, 44 | struct issues_iface_t *issues); 45 | 46 | struct type_iface_t * st_create_subrange_type( 47 | char *storage_type_identifier, 48 | const struct st_location_t *storage_type_identifier_location, 49 | struct subrange_iface_t *subrange, 50 | struct value_iface_t *default_value, 51 | const struct st_location_t *default_value_location, 52 | struct named_ref_pool_iface_t *type_refs, 53 | const struct config_iface_t *config, 54 | struct issues_iface_t *issues); 55 | -------------------------------------------------------------------------------- /src/elements/subrange_case.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | /**************************************************************************/ 24 | /* Value interface */ 25 | /**************************************************************************/ 26 | struct subrange_case_value_t { 27 | struct value_iface_t value; 28 | struct subrange_iface_t *subrange; 29 | }; 30 | 31 | static int subrange_case_value_comparable_to( 32 | const struct value_iface_t *self, 33 | const struct value_iface_t *other_value, 34 | const struct config_iface_t *config, 35 | struct issues_iface_t *issues) 36 | { 37 | struct subrange_case_value_t *sv = 38 | CONTAINER_OF(self, struct subrange_case_value_t, value); 39 | 40 | int min_comparable = sv->subrange->min->comparable_to(sv->subrange->min, 41 | other_value, 42 | config, 43 | issues); 44 | if(min_comparable != ESSTEE_TRUE) 45 | { 46 | issues->new_issue(issues, 47 | "subrange can not be compared to value", 48 | ESSTEE_TYPE_ERROR); 49 | 50 | return ESSTEE_FALSE; 51 | } 52 | 53 | int max_comparable = sv->subrange->max->comparable_to(sv->subrange->max, 54 | other_value, 55 | config, 56 | issues); 57 | if(max_comparable != ESSTEE_TRUE) 58 | { 59 | issues->new_issue(issues, 60 | "subrange can not be compared to value", 61 | ESSTEE_TYPE_ERROR); 62 | 63 | return ESSTEE_FALSE; 64 | } 65 | 66 | return ESSTEE_TRUE; 67 | } 68 | 69 | static int subrange_case_value_equals( 70 | const struct value_iface_t *self, 71 | const struct value_iface_t *other_value, 72 | const struct config_iface_t *config, 73 | struct issues_iface_t *issues) 74 | { 75 | struct subrange_case_value_t *sv = 76 | CONTAINER_OF(self, struct subrange_case_value_t, value); 77 | 78 | int min_greater = sv->subrange->min->greater(sv->subrange->min, 79 | other_value, 80 | config, 81 | issues); 82 | 83 | if(min_greater == ESSTEE_TRUE) 84 | { 85 | return ESSTEE_FALSE; 86 | } 87 | else if(min_greater == ESSTEE_ERROR) 88 | { 89 | return ESSTEE_ERROR; 90 | } 91 | 92 | int max_lesser = sv->subrange->max->lesser(sv->subrange->max, 93 | other_value, 94 | config, 95 | issues); 96 | 97 | if(max_lesser == ESSTEE_TRUE) 98 | { 99 | return ESSTEE_FALSE; 100 | } 101 | else if(max_lesser == ESSTEE_ERROR) 102 | { 103 | return ESSTEE_ERROR; 104 | } 105 | 106 | return ESSTEE_TRUE; 107 | } 108 | 109 | static void subrange_case_value_destroy() 110 | { 111 | /* TODO: subrange case value destroy */ 112 | } 113 | 114 | /**************************************************************************/ 115 | /* Public interface */ 116 | /**************************************************************************/ 117 | struct value_iface_t * st_create_subrange_case_selector( 118 | struct subrange_iface_t *subrange, 119 | const struct config_iface_t *config, 120 | struct issues_iface_t *issues) 121 | { 122 | struct subrange_case_value_t *scv = NULL; 123 | 124 | ALLOC_OR_ERROR_JUMP( 125 | scv, 126 | struct subrange_case_value_t, 127 | issues, 128 | error_free_resources); 129 | 130 | scv->subrange = subrange; 131 | 132 | memset(&(scv->value), 0, sizeof(struct value_iface_t)); 133 | scv->value.comparable_to = subrange_case_value_comparable_to; 134 | scv->value.equals = subrange_case_value_equals; 135 | scv->value.destroy = subrange_case_value_destroy; 136 | 137 | return &(scv->value); 138 | 139 | error_free_resources: 140 | return NULL; 141 | } 142 | -------------------------------------------------------------------------------- /src/elements/subrange_case.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | struct value_iface_t * st_create_subrange_case_selector( 28 | struct subrange_iface_t *subrange, 29 | const struct config_iface_t *config, 30 | struct issues_iface_t *issues); 31 | -------------------------------------------------------------------------------- /src/elements/types.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | 29 | int st_type_general_compatible( 30 | const struct type_iface_t *self, 31 | const struct type_iface_t *other_type, 32 | const struct config_iface_t *config, 33 | struct issues_iface_t *issues) 34 | { 35 | st_bitflag_t self_class = self->class(self); 36 | st_bitflag_t other_type_class = other_type->class(other_type); 37 | 38 | if(self_class == other_type_class) 39 | { 40 | return ESSTEE_TRUE; 41 | } 42 | 43 | /* Clear derived and subrange flags from both types */ 44 | st_bitflag_t self_class_cmp = self_class & (~(DERIVED_TYPE|SUBRANGE_TYPE)); 45 | st_bitflag_t other_type_class_cmp = other_type_class & (~(DERIVED_TYPE|SUBRANGE_TYPE)); 46 | 47 | if(self_class_cmp == other_type_class_cmp) 48 | { 49 | return ESSTEE_TRUE; 50 | } 51 | 52 | const char *self_name = (self->identifier) ? self->identifier : "anonymous type"; 53 | const char *other_name = (other_type->identifier) ? other_type->identifier : "anonymous type"; 54 | 55 | issues->new_issue( 56 | issues, 57 | "types '%s' and '%s' are incompatible", 58 | ESSTEE_TYPE_ERROR, 59 | self_name, 60 | other_name); 61 | 62 | return ESSTEE_FALSE; 63 | } 64 | 65 | struct type_iface_t * st_new_elementary_types() 66 | { 67 | struct type_iface_t *elementary_types = NULL; 68 | struct type_iface_t *types = NULL; 69 | 70 | types = st_new_elementary_integer_types(); 71 | if(!types) 72 | { 73 | return NULL; 74 | } 75 | elementary_types = types; 76 | 77 | types = st_new_elementary_real_types(); 78 | if(!types) 79 | { 80 | st_destroy_types_in_list(elementary_types); 81 | return NULL; 82 | } 83 | DL_CONCAT(elementary_types, types); 84 | 85 | types = st_new_elementary_string_types(); 86 | if(!types) 87 | { 88 | st_destroy_types_in_list(elementary_types); 89 | return NULL; 90 | } 91 | DL_CONCAT(elementary_types, types); 92 | 93 | types = st_new_elementary_date_time_types(); 94 | if(!types) 95 | { 96 | st_destroy_types_in_list(elementary_types); 97 | return NULL; 98 | } 99 | DL_CONCAT(elementary_types, types); 100 | 101 | return elementary_types; 102 | } 103 | 104 | void st_destroy_types_in_list( 105 | struct type_iface_t *types) 106 | { 107 | /* TODO: destroy types in list */ 108 | } 109 | -------------------------------------------------------------------------------- /src/elements/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | int st_type_general_compatible( 27 | const struct type_iface_t *self, 28 | const struct type_iface_t *other_type, 29 | const struct config_iface_t *config, 30 | struct issues_iface_t *issues); 31 | 32 | void st_destroy_types_in_list( 33 | struct type_iface_t *types); 34 | 35 | struct type_iface_t * st_new_elementary_types(); 36 | -------------------------------------------------------------------------------- /src/elements/user_function_blocks.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | struct type_iface_t * st_new_user_function_block( 28 | char *identifier, 29 | const struct st_location_t *location, 30 | struct header_t *header, 31 | struct invoke_iface_t *statements, 32 | struct named_ref_pool_iface_t *type_refs, 33 | struct named_ref_pool_iface_t *var_refs, 34 | const struct config_iface_t *config, 35 | struct issues_iface_t *issues); 36 | -------------------------------------------------------------------------------- /src/elements/user_functions.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | struct function_iface_t * st_new_user_function( 27 | char *identifier, 28 | const struct st_location_t *location, 29 | char *return_type_identifier, 30 | const struct st_location_t *return_type_identifier_location, 31 | struct header_t *header, 32 | struct named_ref_pool_iface_t *global_type_refs, 33 | struct named_ref_pool_iface_t *type_refs, 34 | struct named_ref_pool_iface_t *global_var_refs, 35 | struct named_ref_pool_iface_t *var_refs, 36 | struct invoke_iface_t *statements, 37 | const struct config_iface_t *config, 38 | struct issues_iface_t *issues); 39 | -------------------------------------------------------------------------------- /src/elements/user_programs.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | struct program_iface_t * st_new_user_program( 27 | char *identifier, 28 | const struct st_location_t *location, 29 | struct header_t *header, 30 | struct invoke_iface_t *statements, 31 | struct named_ref_pool_iface_t *type_refs, 32 | struct named_ref_pool_iface_t *var_refs, 33 | const struct config_iface_t *config, 34 | struct issues_iface_t *issues); 35 | 36 | -------------------------------------------------------------------------------- /src/elements/values.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with Foobar. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | st_bitflag_t st_general_value_empty_class( 23 | const struct value_iface_t *self) 24 | { 25 | return 0; 26 | } 27 | 28 | int st_general_value_equals( 29 | const struct value_iface_t *self, 30 | const struct value_iface_t *other_value, 31 | const struct config_iface_t *config, 32 | struct issues_iface_t *issues) 33 | { 34 | int greater = self->greater(self, other_value, config, issues); 35 | if(greater == ESSTEE_TRUE) 36 | { 37 | return ESSTEE_FALSE; 38 | } 39 | 40 | int lesser = self->lesser(self, other_value, config, issues); 41 | if(lesser == ESSTEE_TRUE) 42 | { 43 | return ESSTEE_FALSE; 44 | } 45 | 46 | return ESSTEE_TRUE; 47 | } 48 | -------------------------------------------------------------------------------- /src/elements/values.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | st_bitflag_t st_general_value_empty_class( 25 | const struct value_iface_t *self); 26 | 27 | int st_general_value_equals( 28 | const struct value_iface_t *self, 29 | const struct value_iface_t *other_value, 30 | const struct config_iface_t *config, 31 | struct issues_iface_t *issues); 32 | -------------------------------------------------------------------------------- /src/elements/variable.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | struct variable_stub_t; 26 | 27 | struct variable_stub_t * st_extend_variable_stubs( 28 | struct variable_stub_t *stubs, 29 | char *identifier, 30 | const struct st_location_t *location, 31 | const struct config_iface_t *config, 32 | struct issues_iface_t *issues); 33 | 34 | void st_destroy_variable_stubs( 35 | struct variable_stub_t *stubs); 36 | 37 | struct variable_stub_t * st_set_variable_stubs_type( 38 | struct variable_stub_t *stubs, 39 | struct type_iface_t *type, 40 | const struct config_iface_t *config, 41 | struct issues_iface_t *issue); 42 | 43 | struct variable_stub_t * st_set_variable_stubs_type_name( 44 | struct variable_stub_t *stubs, 45 | char *type_name, 46 | const struct config_iface_t *config, 47 | struct issues_iface_t *issue); 48 | 49 | struct variable_stub_t * st_concatenate_variable_stubs( 50 | struct variable_stub_t *stubs_one, 51 | struct variable_stub_t *stubs_two, 52 | const struct config_iface_t *config, 53 | struct issues_iface_t *issue); 54 | 55 | struct variable_stub_t * st_create_direct_variable_stub( 56 | char *identifier, 57 | struct direct_address_t *address, 58 | char *type_name, 59 | const struct st_location_t *type_name_location, 60 | const struct st_location_t *location, 61 | struct value_iface_t *default_value, 62 | const struct st_location_t *default_value_location, 63 | struct named_ref_pool_iface_t *type_refs, 64 | const struct config_iface_t *config, 65 | struct issues_iface_t *issues); 66 | 67 | struct variable_iface_t * st_create_variable_block( 68 | st_bitflag_t block_class, 69 | st_bitflag_t retain_flag, 70 | st_bitflag_t constant_flag, 71 | struct variable_stub_t *stubs, 72 | struct named_ref_pool_iface_t *global_var_refs, 73 | struct named_ref_pool_iface_t *type_refs, 74 | struct named_ref_pool_iface_t *global_type_refs, 75 | const struct config_iface_t *config, 76 | struct issues_iface_t *issue); 77 | 78 | struct variable_iface_t * st_create_variable_type_name( 79 | char *identifier, 80 | const struct st_location_t *location, 81 | char *type_name, 82 | const struct st_location_t *type_name_location, 83 | st_bitflag_t class, 84 | struct named_ref_pool_iface_t *global_var_refs, 85 | struct named_ref_pool_iface_t *type_refs, 86 | const struct config_iface_t *config, 87 | struct issues_iface_t *issues); 88 | 89 | struct variable_iface_t * st_create_variable_type( 90 | char *identifier, 91 | const struct st_location_t *location, 92 | const struct type_iface_t *type, 93 | st_bitflag_t class, 94 | const struct config_iface_t *config, 95 | struct issues_iface_t *issues); 96 | 97 | -------------------------------------------------------------------------------- /src/esstee/elements.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | struct st_date_tod_t { 28 | uint64_t year; 29 | uint8_t month; 30 | uint8_t day; 31 | uint8_t hours; 32 | uint8_t minutes; 33 | uint8_t seconds; 34 | uint8_t fseconds; 35 | }; 36 | 37 | struct st_duration_t { 38 | double days; 39 | double hours; 40 | double minutes; 41 | double seconds; 42 | double milliseconds; 43 | }; 44 | 45 | struct st_element_t { 46 | 47 | st_bitflag_t (*type_class)( 48 | const struct st_element_t *self); 49 | 50 | const char * (*type_identifier)( 51 | const struct st_element_t *self); 52 | 53 | int (*display)( 54 | const struct st_element_t *self, 55 | char *buffer, 56 | size_t buffer_size); 57 | 58 | struct st_element_t * (*sub_element)( 59 | struct st_element_t *self, 60 | const char *identifier); 61 | 62 | struct st_element_t * (*sub_item)( 63 | struct st_element_t *self, 64 | const char *item); 65 | 66 | int64_t (*as_integer)( 67 | struct st_element_t *self); 68 | 69 | int (*as_bool)( 70 | struct st_element_t *self); 71 | 72 | double (*as_real)( 73 | struct st_element_t *self); 74 | 75 | const char * (*as_text)( 76 | struct st_element_t *self); 77 | 78 | int (*as_duration)( 79 | struct st_element_t *self, 80 | struct st_duration_t *output); 81 | 82 | int (*as_date_tod)( 83 | struct st_element_t *self, 84 | struct st_date_tod_t *output); 85 | 86 | int (*set_by_integer)( 87 | struct st_element_t *self, 88 | int64_t integer); 89 | 90 | int (*set_by_bool)( 91 | struct st_element_t *self, 92 | int bool); 93 | 94 | int (*set_by_real)( 95 | struct st_element_t *self, 96 | double real); 97 | 98 | int (*set_by_text)( 99 | struct st_element_t *self, 100 | const char *text); 101 | 102 | int (*set_by_duration)( 103 | struct st_element_t *self, 104 | const struct st_duration_t *duration); 105 | 106 | int (*set_by_date_tod)( 107 | struct st_element_t *self, 108 | const struct st_date_tod_t *date_tod); 109 | }; 110 | 111 | -------------------------------------------------------------------------------- /src/esstee/esstee.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | struct st_t; 28 | 29 | struct st_t * st_new_instance( 30 | size_t direct_memory_bytes); 31 | 32 | int st_set_config( 33 | const char *option, 34 | int value, 35 | struct st_t *st); 36 | 37 | int st_get_config( 38 | const char *option, 39 | struct st_t *st); 40 | 41 | int st_load_file( 42 | struct st_t *st, 43 | const char *path); 44 | 45 | int st_load_buffer( 46 | const char *identifier, 47 | const char *bytes, 48 | size_t len, 49 | struct st_t *st); 50 | 51 | int st_unload_buffer( 52 | struct st_t *st, 53 | const char *identifier); 54 | 55 | int st_link( 56 | struct st_t *st); 57 | 58 | const struct st_location_t * st_start( 59 | struct st_t *st, 60 | const char *program); 61 | 62 | int st_query( 63 | struct st_t *st, 64 | char *output, 65 | size_t output_max_len, 66 | const char *query); 67 | 68 | struct st_element_t * st_get_element( 69 | struct st_t *st, 70 | const char *identifier); 71 | 72 | const struct st_issue_t * st_fetch_issue( 73 | struct st_t *st, 74 | st_bitflag_t filter); 75 | 76 | const struct st_issue_t * st_fetch_sub_issue( 77 | struct st_t *st, 78 | const struct st_issue_t *issue, 79 | st_bitflag_t filter); 80 | 81 | int st_run_cycle( 82 | struct st_t *st, 83 | uint64_t ms); 84 | 85 | const struct st_location_t * st_step( 86 | struct st_t *st); 87 | 88 | const struct st_location_t * st_step_in( 89 | struct st_t *st); 90 | 91 | const struct st_location_t * st_step_out( 92 | struct st_t *st); 93 | 94 | int st_step_time( 95 | struct st_t *st, 96 | uint64_t ms); 97 | 98 | void st_destroy( 99 | struct st_t *st); 100 | -------------------------------------------------------------------------------- /src/esstee/flags.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | typedef uint64_t st_bitflag_t; 25 | 26 | #define ESSTEE_OK 2 27 | #define ESSTEE_TRUE 1 28 | #define ESSTEE_FALSE 0 29 | #define ESSTEE_ERROR -1 30 | 31 | #define ESSTEE_DIVISION_BY_ZERO -10 32 | #define ESSTEE_TYPE_OVERFLOW -11 33 | #define ESSTEE_TYPE_UNDERFLOW -12 34 | #define ESSTEE_TYPE_INCOMPATIBILITY -13 35 | 36 | #define ESSTEE_GENERAL_ERROR_ISSUE (1 << 0) 37 | #define ESSTEE_GENERAL_WARNING_ISSUE (1 << 1) 38 | 39 | #define ESSTEE_INTERNAL_ERROR (1 << 0) 40 | #define ESSTEE_MEMORY_ERROR (1 << 1) 41 | #define ESSTEE_SYNTAX_ERROR (1 << 2) 42 | #define ESSTEE_PARSE_ERROR (1 << 3) 43 | #define ESSTEE_LINK_ERROR (1 << 4) 44 | #define ESSTEE_RUNTIME_ERROR (1 << 5) 45 | #define ESSTEE_ARGUMENT_ERROR (1 << 6) 46 | #define ESSTEE_CONTEXT_ERROR (1 << 7) 47 | #define ESSTEE_TYPE_ERROR (1 << 8) 48 | #define ESSTEE_IO_ERROR (1 << 9) 49 | 50 | #define ESSTEE_SYNTAX_WARNING (1 << 10) 51 | #define ESSTEE_BUFFER_WARNING (1 << 11) 52 | 53 | #define ESSTEE_FILTER_ANY_ERROR 0x3ff 54 | #define ESSTEE_FILTER_ANY_WARNING (1 << 9) 55 | #define ESSTEE_FILTER_ANY_ISSUE 0xffffffffffffffff 56 | 57 | #define ISSUE_ERROR_CLASS (1 << 0) 58 | #define ISSUE_WARNING_CLASS (1 << 1) 59 | 60 | #define ESSTEE_TYPE_INTEGER_NUMERIC_CLASS (1 << 0) 61 | #define ESSTEE_TYPE_INTEGER_BITDATA_CLASS (1 << 1) 62 | #define ESSTEE_TYPE_REAL_NUMERIC_CLASS (1 << 2) 63 | #define ESSTEE_TYPE_INTEGER_SIGNED (1 << 3) 64 | #define ESSTEE_TYPE_INTEGER_UNSIGNED (1 << 4) 65 | #define ESSTEE_TYPE_BOOL (1 << 5) 66 | #define ESSTEE_TYPE_SINT (1 << 6) 67 | #define ESSTEE_TYPE_INT (1 << 7) 68 | #define ESSTEE_TYPE_DINT (1 << 8) 69 | #define ESSTEE_TYPE_LINT (1 << 9) 70 | #define ESSTEE_TYPE_USINT (1 << 10) 71 | #define ESSTEE_TYPE_UINT (1 << 11) 72 | #define ESSTEE_TYPE_UDINT (1 << 12) 73 | #define ESSTEE_TYPE_ULINT (1 << 13) 74 | #define ESSTEE_TYPE_BYTE (1 << 14) 75 | #define ESSTEE_TYPE_WORD (1 << 15) 76 | #define ESSTEE_TYPE_DWORD (1 << 16) 77 | #define ESSTEE_TYPE_LWORD (1 << 17) 78 | #define ESSTEE_TYPE_REAL (1 << 18) 79 | #define ESSTEE_TYPE_LREAL (1 << 19) 80 | #define ESSTEE_TYPE_STRING (1 << 20) 81 | #define ESSTEE_TYPE_WSTRING (1 << 21) 82 | #define ESSTEE_TYPE_DURATION (1 << 22) 83 | #define ESSTEE_TYPE_DATE (1 << 23) 84 | #define ESSTEE_TYPE_TOD (1 << 24) 85 | #define ESSTEE_TYPE_DATE_TOD (1 << 25) 86 | #define ESSTEE_TYPE_DERIVED (1 << 26) 87 | #define ESSTEE_TYPE_ENUM (1 << 27) 88 | #define ESSTEE_TYPE_SUBRANGE (1 << 28) 89 | #define ESSTEE_TYPE_ARRAY (1 << 29) 90 | #define ESSTEE_TYPE_STRUCT (1 << 30) 91 | #define ESSTEE_TYPE_FB (1 << 31) 92 | -------------------------------------------------------------------------------- /src/esstee/issues.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | struct st_issue_t { 26 | char *message; 27 | st_bitflag_t class; 28 | int has_sub_issues; 29 | struct st_location_t *locations; 30 | }; 31 | -------------------------------------------------------------------------------- /src/esstee/locations.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | struct st_location_t { 23 | const char *source; 24 | int first_line; 25 | int first_column; 26 | int last_line; 27 | int last_column; 28 | struct st_location_t *prev; 29 | struct st_location_t *next; 30 | }; 31 | -------------------------------------------------------------------------------- /src/expressions/direct_address_term.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | struct expression_iface_t * st_create_direct_address_term( 26 | struct direct_address_t *address, 27 | const struct st_location_t *location, 28 | const struct config_iface_t *config, 29 | struct issues_iface_t *issues); 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/expressions/function_invocation.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | struct expression_iface_t * st_create_function_invocation_term( 27 | char *function_identifier, 28 | const struct st_location_t *location, 29 | struct named_ref_pool_iface_t *function_refs, 30 | struct invoke_parameters_iface_t *invoke_parameters, 31 | const struct config_iface_t *config, 32 | struct issues_iface_t *issues); 33 | -------------------------------------------------------------------------------- /src/expressions/identifier.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | struct expression_iface_t * st_create_identifier_term( 26 | char *identifier, 27 | const struct st_location_t *location, 28 | struct named_ref_pool_iface_t *var_refs, 29 | const struct config_iface_t *config, 30 | struct issues_iface_t *issues); 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/expressions/iexpression.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | struct expression_iface_t { 27 | 28 | struct invoke_iface_t invoke; 29 | 30 | const struct value_iface_t * (*return_value)( 31 | const struct expression_iface_t *self); 32 | 33 | struct expression_iface_t * (*clone)( 34 | struct expression_iface_t *self, 35 | struct issues_iface_t *issues); 36 | 37 | void (*destroy)( 38 | struct expression_iface_t *self); 39 | }; 40 | -------------------------------------------------------------------------------- /src/expressions/inline_expression.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | /**************************************************************************/ 24 | /* Expression interface */ 25 | /**************************************************************************/ 26 | struct value_expression_t { 27 | struct expression_iface_t expression; 28 | struct st_location_t *location; 29 | struct value_iface_t *value; 30 | }; 31 | 32 | static const struct value_iface_t * value_expression_return_value( 33 | const struct expression_iface_t *self) 34 | { 35 | const struct value_expression_t *ve 36 | = CONTAINER_OF(self, struct value_expression_t, expression); 37 | 38 | return ve->value; 39 | } 40 | 41 | static void value_expression_destroy( 42 | struct expression_iface_t *self) 43 | { 44 | /* TODO: value expression destructor */ 45 | } 46 | 47 | /**************************************************************************/ 48 | /* Public interface */ 49 | /**************************************************************************/ 50 | struct expression_iface_t * st_create_value_expression( 51 | struct value_iface_t *value, 52 | const struct st_location_t *location, 53 | const struct config_iface_t *config, 54 | struct issues_iface_t *issues) 55 | { 56 | struct value_expression_t *ve = NULL; 57 | struct st_location_t *value_location = NULL; 58 | 59 | ALLOC_OR_ERROR_JUMP( 60 | ve, 61 | struct value_expression_t, 62 | issues, 63 | error_free_resources); 64 | 65 | LOCDUP_OR_ERROR_JUMP( 66 | value_location, 67 | location, 68 | issues, 69 | error_free_resources); 70 | 71 | ve->location = value_location; 72 | ve->value = value; 73 | 74 | memset(&(ve->expression), 0, sizeof(struct expression_iface_t)); 75 | 76 | ve->expression.invoke.location = ve->location; 77 | ve->expression.return_value = value_expression_return_value; 78 | ve->expression.destroy = value_expression_destroy; 79 | 80 | return &(ve->expression); 81 | 82 | error_free_resources: 83 | free(ve); 84 | return NULL; 85 | } 86 | -------------------------------------------------------------------------------- /src/expressions/inline_expression.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | struct expression_iface_t * st_create_value_expression( 25 | struct value_iface_t *value, 26 | const struct st_location_t *location, 27 | const struct config_iface_t *config, 28 | struct issues_iface_t *issues); 29 | 30 | -------------------------------------------------------------------------------- /src/expressions/negative_prefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | struct expression_iface_t * st_create_negative_prefix_term( 25 | struct expression_iface_t *term, 26 | const struct st_location_t *location, 27 | const struct config_iface_t *config, 28 | struct issues_iface_t *issues); 29 | 30 | struct expression_iface_t * st_create_not_prefix_term( 31 | struct expression_iface_t *term, 32 | const struct st_location_t *location, 33 | const struct config_iface_t *config, 34 | struct issues_iface_t *issues); 35 | -------------------------------------------------------------------------------- /src/expressions/qualified_identifier_term.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | struct expression_iface_t * st_create_qualified_identifier_term( 27 | struct qualified_identifier_iface_t *qualified_identifier, 28 | const struct st_location_t *location, 29 | const struct config_iface_t *config, 30 | struct issues_iface_t *issues); 31 | -------------------------------------------------------------------------------- /src/linker/linker.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | struct type_iface_t * st_link_types( 31 | struct type_iface_t *type_list, 32 | struct type_iface_t *type_table, 33 | struct issues_iface_t *errors); 34 | 35 | struct variable_iface_t * st_link_variables( 36 | struct variable_iface_t *variable_list, 37 | struct variable_iface_t *variable_table, 38 | struct issues_iface_t *errors); 39 | 40 | struct function_iface_t * st_link_functions( 41 | struct function_iface_t *function_list, 42 | struct function_iface_t *function_table, 43 | struct issues_iface_t *issues); 44 | 45 | struct program_iface_t * st_link_programs( 46 | struct program_iface_t *program_list, 47 | struct program_iface_t *program_table, 48 | struct issues_iface_t *issues); 49 | 50 | void st_resolve_type_refs( 51 | struct named_ref_pool_iface_t *type_ref_pool, 52 | struct type_iface_t *type_table); 53 | 54 | void st_resolve_var_refs( 55 | struct named_ref_pool_iface_t *var_ref_pool, 56 | struct variable_iface_t *var_table); 57 | 58 | int st_resolve_function_refs( 59 | struct named_ref_pool_iface_t *function_ref_pool, 60 | struct function_iface_t *function_table); 61 | 62 | void st_resolve_program_refs( 63 | struct named_ref_pool_iface_t *prgm_ref_pool, 64 | struct program_iface_t *prgm_table); 65 | -------------------------------------------------------------------------------- /src/parser/pcases.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | struct case_list_element_t * st_append_case_value( 27 | struct case_list_element_t *case_list, 28 | struct value_iface_t *case_value, 29 | const struct st_location_t *case_value_location, 30 | struct parser_t *parser) 31 | { 32 | struct case_list_element_t *list = st_extend_case_list( 33 | case_list, 34 | case_value, 35 | case_value_location, 36 | parser->config, 37 | parser->errors); 38 | 39 | if(!list) 40 | { 41 | st_destroy_case_list(case_list); 42 | case_value->destroy(case_value); 43 | } 44 | 45 | return list; 46 | } 47 | 48 | struct case_t * st_new_case( 49 | struct case_list_element_t *case_value_list, 50 | const struct st_location_t *location, 51 | struct invoke_iface_t *statements, 52 | struct parser_t *parser) 53 | { 54 | struct case_t *c = st_create_case(case_value_list, 55 | location, 56 | statements, 57 | parser->config, 58 | parser->errors); 59 | 60 | if(!c) 61 | { 62 | st_destroy_case_list(case_value_list); 63 | st_destroy_statements(statements); 64 | } 65 | 66 | return c; 67 | } 68 | 69 | struct case_t * st_append_case( 70 | struct case_t *cases, 71 | struct case_t *new_case, 72 | struct parser_t *parser) 73 | { 74 | struct case_t *extended_cases = st_extend_cases(cases, 75 | new_case, 76 | parser->config, 77 | parser->errors); 78 | if(!extended_cases) 79 | { 80 | st_destroy_case(cases); 81 | st_destroy_case(new_case); 82 | } 83 | 84 | return extended_cases; 85 | } 86 | 87 | struct value_iface_t * st_new_subrange_case_value( 88 | struct subrange_iface_t *subrange, 89 | struct parser_t *parser) 90 | { 91 | struct value_iface_t *scv = st_create_subrange_case_selector( 92 | subrange, 93 | parser->config, 94 | parser->errors); 95 | 96 | if(scv) 97 | { 98 | subrange->destroy(subrange); 99 | } 100 | 101 | return scv; 102 | } 103 | -------------------------------------------------------------------------------- /src/parser/pconditionals.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | struct if_statement_t * st_new_elsif_clause( 26 | struct expression_iface_t *condition, 27 | const struct st_location_t *condition_location, 28 | struct invoke_iface_t *true_statements, 29 | const struct st_location_t *location, 30 | struct parser_t *parser) 31 | { 32 | struct if_statement_t *clause = st_create_elsif_clause( 33 | condition, 34 | condition_location, 35 | true_statements, 36 | location, 37 | parser->config, 38 | parser->errors); 39 | 40 | if(!clause) 41 | { 42 | condition->destroy(condition); 43 | st_destroy_statements(true_statements); 44 | } 45 | 46 | return clause; 47 | } 48 | 49 | struct if_statement_t * st_append_elsif_clause( 50 | struct if_statement_t *elsif_clauses, 51 | struct if_statement_t *elsif_clause, 52 | const struct st_location_t *location, 53 | struct parser_t *parser) 54 | { 55 | struct if_statement_t *new_clauses = st_extend_elsif_clauses( 56 | elsif_clauses, 57 | elsif_clause, 58 | location, 59 | parser->config, 60 | parser->errors); 61 | 62 | if(!new_clauses) 63 | { 64 | st_destroy_elsif_clauses(elsif_clauses); 65 | st_destroy_elsif_clauses(elsif_clause); 66 | } 67 | 68 | return new_clauses; 69 | } 70 | -------------------------------------------------------------------------------- /src/parser/penums.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | 24 | struct value_iface_t * st_new_enum_value( 25 | char *identifier, 26 | const struct st_location_t *location, 27 | struct parser_t *parser) 28 | { 29 | struct value_iface_t *ev = st_create_enum_value(identifier, 30 | location, 31 | parser->config, 32 | parser->errors); 33 | if(!ev) 34 | { 35 | goto error_free_resources; 36 | } 37 | 38 | return ev; 39 | 40 | error_free_resources: 41 | free(identifier); 42 | return NULL; 43 | } 44 | 45 | struct enum_group_iface_t * st_append_new_enum_item( 46 | struct enum_group_iface_t *enum_group, 47 | char *identifier, 48 | const struct st_location_t *location, 49 | struct parser_t *parser) 50 | { 51 | if(!enum_group) 52 | { 53 | enum_group = st_create_enum_group(parser->config, 54 | parser->errors); 55 | 56 | if(!enum_group) 57 | { 58 | goto error_free_resources; 59 | } 60 | } 61 | 62 | int extend_result = enum_group->extend(enum_group, 63 | identifier, 64 | location, 65 | parser->config, 66 | parser->errors); 67 | if(extend_result != ESSTEE_OK) 68 | { 69 | goto error_free_resources; 70 | } 71 | 72 | return enum_group; 73 | 74 | error_free_resources: 75 | if(enum_group) 76 | { 77 | enum_group->destroy(enum_group); 78 | } 79 | free(identifier); 80 | return NULL; 81 | } 82 | -------------------------------------------------------------------------------- /src/parser/pheader.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | 26 | struct header_t * st_append_types_to_header( 27 | struct header_t *header, 28 | struct type_iface_t *type_block, 29 | struct parser_t *parser) 30 | { 31 | if(!header) 32 | { 33 | ALLOC_OR_ERROR_JUMP( 34 | header, 35 | struct header_t, 36 | parser->errors, 37 | error_free_resources); 38 | 39 | header->types = NULL; 40 | header->variables = NULL; 41 | } 42 | 43 | DL_CONCAT(header->types, type_block); 44 | return header; 45 | 46 | error_free_resources: 47 | return NULL; 48 | } 49 | 50 | struct header_t * st_append_vars_to_header( 51 | struct header_t *header, 52 | struct variable_iface_t *var_block, 53 | struct parser_t *parser) 54 | { 55 | if(!header) 56 | { 57 | ALLOC_OR_ERROR_JUMP( 58 | header, 59 | struct header_t, 60 | parser->errors, 61 | error_free_resources); 62 | 63 | header->types = NULL; 64 | header->variables = NULL; 65 | } 66 | 67 | if(var_block) 68 | { 69 | if(ST_FLAG_IS_SET(var_block->class, GLOBAL_VAR_CLASS)) 70 | { 71 | DL_CONCAT(parser->global_variables, var_block); 72 | } 73 | else 74 | { 75 | DL_CONCAT(header->variables, var_block); 76 | } 77 | } 78 | 79 | return header; 80 | 81 | error_free_resources: 82 | /* TODO: clear named references in header */ 83 | // TODO: destroy vars block 84 | return NULL; 85 | } 86 | -------------------------------------------------------------------------------- /src/parser/pinvokeparameters.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | 24 | struct invoke_parameter_t * st_new_invoke_parameter( 25 | char *identifier, 26 | const struct st_location_t *location, 27 | struct expression_iface_t *assigned, 28 | struct parser_t *parser) 29 | { 30 | struct invoke_parameter_t *param = st_create_invoke_parameter(identifier, 31 | location, 32 | assigned, 33 | parser->config, 34 | parser->errors); 35 | 36 | if(!param) 37 | { 38 | free(identifier); 39 | assigned->destroy(assigned); 40 | } 41 | 42 | return param; 43 | } 44 | 45 | struct invoke_parameters_iface_t * st_append_invoke_parameter( 46 | struct invoke_parameters_iface_t *parameter_group, 47 | struct invoke_parameter_t *new_parameter, 48 | struct parser_t *parser) 49 | { 50 | if(!parameter_group) 51 | { 52 | parameter_group = st_create_invoke_parameters(new_parameter, 53 | parser->config, 54 | parser->errors); 55 | 56 | if(!parameter_group) 57 | { 58 | st_destroy_invoke_parameter(new_parameter); 59 | return NULL; 60 | } 61 | else 62 | { 63 | return parameter_group; 64 | } 65 | } 66 | 67 | int append_result = parameter_group->append(parameter_group, 68 | new_parameter, 69 | parser->config, 70 | parser->errors); 71 | if(append_result != ESSTEE_OK) 72 | { 73 | parameter_group->destroy(parameter_group); 74 | st_destroy_invoke_parameter(new_parameter); 75 | parameter_group = NULL; 76 | } 77 | 78 | return parameter_group; 79 | } 80 | -------------------------------------------------------------------------------- /src/parser/ppous.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | 29 | int st_new_function_pou( 30 | char *identifier, 31 | const struct st_location_t *location, 32 | char *return_type_identifier, 33 | const struct st_location_t *return_type_identifier_location, 34 | struct header_t *header, 35 | struct invoke_iface_t *statements, 36 | struct parser_t *parser) 37 | { 38 | struct function_iface_t *function = st_new_user_function( 39 | identifier, 40 | location, 41 | return_type_identifier, 42 | return_type_identifier_location, 43 | header, 44 | parser->global_type_ref_pool, 45 | parser->pou_type_ref_pool, 46 | parser->global_var_ref_pool, 47 | parser->pou_var_ref_pool, 48 | statements, 49 | parser->config, 50 | parser->errors); 51 | 52 | if(!function) 53 | { 54 | free(return_type_identifier); 55 | st_destroy_header(header); 56 | st_destroy_statements(statements); 57 | } 58 | else 59 | { 60 | parser->pou_type_ref_pool = NULL; 61 | parser->pou_var_ref_pool = NULL; 62 | } 63 | 64 | if(function) 65 | { 66 | /* TODO: commit of references */ 67 | DL_APPEND(parser->functions, function); 68 | return ESSTEE_OK; 69 | } 70 | 71 | /* TODO: check clearing of references */ 72 | return ESSTEE_ERROR; 73 | } 74 | 75 | int st_new_function_block_pou( 76 | char *identifier, 77 | const struct st_location_t *location, 78 | struct header_t *header, 79 | struct invoke_iface_t *statements, 80 | struct parser_t *parser) 81 | { 82 | struct type_iface_t *fb = st_new_user_function_block( 83 | identifier, 84 | location, 85 | header, 86 | statements, 87 | parser->pou_type_ref_pool, 88 | parser->pou_var_ref_pool, 89 | parser->config, 90 | parser->errors); 91 | 92 | if(!fb) 93 | { 94 | free(identifier); 95 | st_destroy_header(header); 96 | st_destroy_statements(statements); 97 | } 98 | else 99 | { 100 | parser->pou_type_ref_pool = NULL; 101 | parser->pou_var_ref_pool = NULL; 102 | } 103 | 104 | if(fb) 105 | { 106 | DL_APPEND(parser->global_types, fb); 107 | DL_APPEND(parser->function_blocks, fb->function_block_handle(fb)); 108 | return ESSTEE_OK; 109 | } 110 | 111 | return ESSTEE_ERROR; 112 | } 113 | 114 | 115 | int st_new_program_pou( 116 | char *identifier, 117 | const struct st_location_t *location, 118 | struct header_t *header, 119 | struct invoke_iface_t *statements, 120 | struct parser_t *parser) 121 | { 122 | struct program_iface_t *program = st_new_user_program( 123 | identifier, 124 | location, 125 | header, 126 | statements, 127 | parser->pou_type_ref_pool, 128 | parser->pou_var_ref_pool, 129 | parser->config, 130 | parser->errors); 131 | 132 | if(!program) 133 | { 134 | free(identifier); 135 | st_destroy_header(header); 136 | st_destroy_statements(statements); 137 | } 138 | else 139 | { 140 | parser->pou_type_ref_pool = NULL; 141 | parser->pou_var_ref_pool = NULL; 142 | } 143 | 144 | if(st_reset_parser_next_pou(parser) == ESSTEE_OK) 145 | { 146 | if(program) 147 | { 148 | DL_APPEND(parser->programs, program); 149 | return ESSTEE_OK; 150 | } 151 | } 152 | 153 | return ESSTEE_ERROR; 154 | } 155 | 156 | int st_new_type_block_pou( 157 | struct type_iface_t *types, 158 | struct parser_t *parser) 159 | { 160 | DL_CONCAT(parser->global_types, types); 161 | 162 | parser->global_type_ref_pool->merge(parser->global_type_ref_pool, 163 | parser->pou_type_ref_pool); 164 | 165 | return st_reset_parser_next_pou(parser); 166 | } 167 | 168 | int st_new_var_block_pou( 169 | struct variable_iface_t *variables, 170 | struct parser_t *parser) 171 | { 172 | DL_CONCAT(parser->global_variables, variables); 173 | 174 | parser->global_type_ref_pool->merge(parser->global_type_ref_pool, 175 | parser->pou_type_ref_pool); 176 | 177 | return st_reset_parser_next_pou(parser); 178 | } 179 | -------------------------------------------------------------------------------- /src/parser/pquery.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | 28 | struct query_t * st_new_query_by_program( 29 | char *prgm_identifier, 30 | const struct st_location_t *prgm_location, 31 | struct parser_t *parser) 32 | { 33 | struct query_t *query = st_create_program_query( 34 | prgm_identifier, 35 | prgm_location, 36 | parser->program_ref_pool, 37 | parser->config, 38 | parser->errors); 39 | 40 | if(!query) 41 | { 42 | free(prgm_identifier); 43 | } 44 | 45 | return query; 46 | } 47 | 48 | struct query_t * st_new_query_by_identifier( 49 | char *prgm_identifier, 50 | const struct st_location_t *prgm_location, 51 | char *identifier, 52 | const struct st_location_t *identifier_location, 53 | struct expression_iface_t *assigned, 54 | struct parser_t *parser) 55 | { 56 | struct query_t *query = st_create_identifier_query( 57 | prgm_identifier, 58 | prgm_location, 59 | identifier, 60 | identifier_location, 61 | assigned, 62 | parser->program_ref_pool, 63 | parser->pou_var_ref_pool, 64 | parser->config, 65 | parser->errors); 66 | 67 | if(!query) 68 | { 69 | free(prgm_identifier); 70 | free(identifier); 71 | assigned->destroy(assigned); 72 | } 73 | 74 | return query; 75 | } 76 | 77 | struct query_t * st_new_query_by_qualified_identifier( 78 | char *prgm_identifier, 79 | const struct st_location_t *prgm_location, 80 | struct qualified_identifier_iface_t *qid, 81 | struct expression_iface_t *assigned, 82 | struct parser_t *parser) 83 | { 84 | struct query_t *query = st_create_qualified_identifier_query( 85 | prgm_identifier, 86 | prgm_location, 87 | qid, 88 | assigned, 89 | parser->program_ref_pool, 90 | parser->config, 91 | parser->errors); 92 | 93 | if(!query) 94 | { 95 | free(prgm_identifier); 96 | qid->destroy(qid); 97 | assigned->destroy(assigned); 98 | } 99 | 100 | return query; 101 | } 102 | 103 | int st_append_query( 104 | struct query_t *query, 105 | struct parser_t *parser) 106 | { 107 | if(parser->queries) 108 | { 109 | int append_result = parser->queries->append(parser->queries, 110 | query, 111 | parser->config, 112 | parser->errors); 113 | if(append_result != ESSTEE_OK) 114 | { 115 | goto error_free_resources; 116 | } 117 | } 118 | else 119 | { 120 | parser->queries = st_create_queries(query, 121 | parser->config, 122 | parser->errors); 123 | 124 | if(!parser->queries) 125 | { 126 | goto error_free_resources; 127 | } 128 | } 129 | 130 | return ESSTEE_OK; 131 | 132 | error_free_resources: 133 | st_destroy_query(query); 134 | return ESSTEE_ERROR; 135 | } 136 | 137 | int st_finish_queries( 138 | struct parser_t *parser) 139 | { 140 | int finish_result = parser->queries->finish(parser->queries, 141 | parser->pou_var_ref_pool, 142 | parser->function_ref_pool, 143 | parser->program_ref_pool, 144 | parser->config, 145 | parser->errors); 146 | 147 | if(finish_result == ESSTEE_OK) 148 | { 149 | parser->pou_var_ref_pool = NULL; 150 | parser->function_ref_pool = NULL; 151 | parser->program_ref_pool = NULL; 152 | } 153 | 154 | return finish_result; 155 | } 156 | -------------------------------------------------------------------------------- /src/parser/pstruct.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | 24 | struct struct_elements_iface_t * st_add_new_struct_element( 25 | struct struct_elements_iface_t *elements, 26 | char *identifier, 27 | const struct st_location_t *identifier_location, 28 | struct type_iface_t *type, 29 | struct parser_t *parser) 30 | { 31 | if(!elements) 32 | { 33 | elements = st_create_struct_elements(parser->config, 34 | parser->errors); 35 | 36 | if(!elements) 37 | { 38 | goto error_free_resources; 39 | } 40 | } 41 | 42 | int extend_result = elements->extend_by_type(elements, 43 | identifier, 44 | identifier_location, 45 | type, 46 | parser->config, 47 | parser->errors); 48 | 49 | if(extend_result != ESSTEE_OK) 50 | { 51 | goto error_free_resources; 52 | } 53 | 54 | return elements; 55 | 56 | error_free_resources: 57 | if(elements) 58 | { 59 | elements->destroy(elements); 60 | } 61 | type->destroy(type); 62 | free(identifier); 63 | return NULL; 64 | } 65 | 66 | struct struct_elements_iface_t * st_add_new_struct_element_by_name( 67 | struct struct_elements_iface_t *elements, 68 | char *identifier, 69 | const struct st_location_t *identifier_location, 70 | char *type_name, 71 | const struct st_location_t *type_name_location, 72 | struct parser_t *parser) 73 | { 74 | if(!elements) 75 | { 76 | elements = st_create_struct_elements(parser->config, 77 | parser->errors); 78 | 79 | if(!elements) 80 | { 81 | goto error_free_resources; 82 | } 83 | } 84 | 85 | int extend_result = elements->extend_by_type_name(elements, 86 | identifier, 87 | identifier_location, 88 | type_name, 89 | type_name_location, 90 | parser->pou_type_ref_pool, 91 | parser->config, 92 | parser->errors); 93 | 94 | if(extend_result != ESSTEE_OK) 95 | { 96 | goto error_free_resources; 97 | } 98 | 99 | return elements; 100 | 101 | error_free_resources: 102 | if(elements) 103 | { 104 | elements->destroy(elements); 105 | } 106 | free(type_name); 107 | free(identifier); 108 | return NULL; 109 | } 110 | 111 | struct value_iface_t * st_struct_initializer_value( 112 | struct struct_initializer_iface_t *initializer, 113 | struct parser_t *parser) 114 | { 115 | return initializer->value(initializer); 116 | } 117 | 118 | struct struct_initializer_iface_t * st_add_new_struct_element_initializer( 119 | struct struct_initializer_iface_t *initializer, 120 | char *identifier, 121 | const struct st_location_t *identifier_location, 122 | struct value_iface_t *value, 123 | struct parser_t *parser) 124 | { 125 | if(!initializer) 126 | { 127 | initializer = st_create_struct_initializer(parser->config, 128 | parser->errors); 129 | 130 | if(!initializer) 131 | { 132 | goto error_free_resources; 133 | } 134 | } 135 | 136 | int extend_result = initializer->extend(initializer, 137 | identifier, 138 | identifier_location, 139 | value, 140 | parser->config, 141 | parser->errors); 142 | 143 | if(extend_result != ESSTEE_OK) 144 | { 145 | goto error_free_resources; 146 | } 147 | 148 | return initializer; 149 | 150 | error_free_resources: 151 | if(initializer) 152 | { 153 | initializer->destroy(initializer); 154 | } 155 | value->destroy(value); 156 | free(identifier); 157 | return NULL; 158 | } 159 | -------------------------------------------------------------------------------- /src/parser/psubrange.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | 24 | struct subrange_iface_t * st_new_subrange( 25 | struct value_iface_t *min, 26 | const struct st_location_t *min_location, 27 | struct value_iface_t *max, 28 | const struct st_location_t *max_location, 29 | const struct st_location_t *location, 30 | struct parser_t *parser) 31 | { 32 | struct subrange_iface_t *sr = st_create_subrange(min, 33 | min_location, 34 | max, 35 | max_location, 36 | location, 37 | parser->config, 38 | parser->errors); 39 | if(!sr) 40 | { 41 | min->destroy(min); 42 | max->destroy(max); 43 | } 44 | 45 | return sr; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /src/parser/pvalues.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | /**************************************************************************/ 24 | /* Inline values */ 25 | /**************************************************************************/ 26 | 27 | -------------------------------------------------------------------------------- /src/parser/scanneroptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | struct scanner_options_t { 23 | int query_mode_start; 24 | }; 25 | -------------------------------------------------------------------------------- /src/rt/cursor.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | struct cursor_iface_t * st_new_cursor(); 25 | -------------------------------------------------------------------------------- /src/rt/icursor.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | struct cursor_iface_t { 27 | 28 | struct invoke_iface_t * (*step)( 29 | struct cursor_iface_t *self, 30 | struct systime_iface_t *systime, 31 | const struct config_iface_t *config, 32 | struct issues_iface_t *issues); 33 | 34 | struct invoke_iface_t * (*step_in)( 35 | struct cursor_iface_t *self, 36 | struct systime_iface_t *systime, 37 | const struct config_iface_t *config, 38 | struct issues_iface_t *issues); 39 | 40 | struct invoke_iface_t * (*step_out)( 41 | struct cursor_iface_t *self, 42 | struct systime_iface_t *systime, 43 | const struct config_iface_t *config, 44 | struct issues_iface_t *issues); 45 | 46 | void (*reset)( 47 | struct cursor_iface_t *self); 48 | 49 | int (*switch_current)( 50 | struct cursor_iface_t *self, 51 | struct invoke_iface_t *switch_to, 52 | const struct config_iface_t *config, 53 | struct issues_iface_t *issues); 54 | 55 | int (*switch_cycle_start)( 56 | struct cursor_iface_t *self, 57 | struct invoke_iface_t *start, 58 | const struct config_iface_t *config, 59 | struct issues_iface_t *issues); 60 | 61 | void (*push_return_context)( 62 | struct cursor_iface_t *self, 63 | struct invoke_iface_t *context); 64 | 65 | void (*pop_return_context)( 66 | struct cursor_iface_t *self); 67 | 68 | int (*jump_return)( 69 | struct cursor_iface_t *self); 70 | 71 | void (*push_exit_context)( 72 | struct cursor_iface_t *self, 73 | struct invoke_iface_t *context); 74 | 75 | void (*pop_exit_context)( 76 | struct cursor_iface_t *self); 77 | 78 | int (*jump_exit)( 79 | struct cursor_iface_t *self); 80 | 81 | const struct st_location_t * (*current_location)( 82 | struct cursor_iface_t *self); 83 | 84 | void (*destroy)( 85 | struct cursor_iface_t *self); 86 | 87 | }; 88 | -------------------------------------------------------------------------------- /src/rt/isystime.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | struct systime_iface_t { 25 | 26 | int (*reset)( 27 | struct systime_iface_t *self); 28 | 29 | uint64_t (*get_time_ms)( 30 | struct systime_iface_t *self); 31 | 32 | uint64_t (*add_time_ms)( 33 | struct systime_iface_t *self, 34 | uint64_t ms); 35 | 36 | uint64_t (*elapsed_from)( 37 | struct systime_iface_t *self, 38 | uint64_t timestamp); 39 | }; 40 | -------------------------------------------------------------------------------- /src/rt/systime.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | 27 | struct systime_iface_t * st_new_systime(void) 28 | { 29 | struct systime_t *syst = NULL; 30 | ALLOC_OR_JUMP( 31 | syst, 32 | struct systime_t, 33 | error_free_resources); 34 | 35 | syst->systime.add_time_ms = st_systime_add_time_ms; 36 | syst->systime.get_time_ms = st_systime_get_time_ms; 37 | syst->systime.reset = st_systime_reset; 38 | 39 | return &(syst->systime); 40 | 41 | error_free_resources: 42 | return NULL; 43 | } 44 | 45 | int st_systime_reset( 46 | struct systime_iface_t *self) 47 | { 48 | struct systime_t *syst = 49 | CONTAINER_OF(self, struct systime_t, systime); 50 | 51 | syst->current_time = 0; 52 | 53 | return ESSTEE_OK; 54 | } 55 | 56 | uint64_t st_systime_get_time_ms( 57 | struct systime_iface_t *self) 58 | { 59 | struct systime_t *syst = 60 | CONTAINER_OF(self, struct systime_t, systime); 61 | 62 | return syst->current_time; 63 | } 64 | 65 | uint64_t st_systime_add_time_ms( 66 | struct systime_iface_t *self, 67 | uint64_t ms) 68 | { 69 | struct systime_t *syst = 70 | CONTAINER_OF(self, struct systime_t, systime); 71 | 72 | syst->current_time += ms; 73 | 74 | return ESSTEE_OK; 75 | } 76 | -------------------------------------------------------------------------------- /src/rt/systime.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | 25 | struct systime_t { 26 | struct systime_iface_t systime; 27 | uint64_t current_time; 28 | }; 29 | 30 | struct systime_iface_t * st_new_systime(void); 31 | 32 | int st_systime_reset( 33 | struct systime_iface_t *self); 34 | 35 | uint64_t st_systime_get_time_ms( 36 | struct systime_iface_t *self); 37 | 38 | uint64_t st_systime_add_time_ms( 39 | struct systime_iface_t *self, 40 | uint64_t ms); 41 | -------------------------------------------------------------------------------- /src/statements/case.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | struct case_list_element_t; 27 | struct case_t; 28 | 29 | struct case_list_element_t * st_extend_case_list( 30 | struct case_list_element_t *case_list, 31 | struct value_iface_t *value, 32 | const struct st_location_t *case_value_location, 33 | const struct config_iface_t *config, 34 | struct issues_iface_t *issues); 35 | 36 | void st_destroy_case_list( 37 | struct case_list_element_t *case_list); 38 | 39 | struct case_t * st_create_case( 40 | struct case_list_element_t *case_list, 41 | const struct st_location_t *location, 42 | struct invoke_iface_t *statements, 43 | const struct config_iface_t *config, 44 | struct issues_iface_t *issues); 45 | 46 | void st_destroy_case( 47 | struct case_t *c); 48 | 49 | struct case_t * st_extend_cases( 50 | struct case_t *cases, 51 | struct case_t *new_case, 52 | const struct config_iface_t *config, 53 | struct issues_iface_t *issues); 54 | 55 | struct invoke_iface_t * st_create_case_statement( 56 | struct expression_iface_t *selector, 57 | struct case_t *cases, 58 | struct invoke_iface_t *else_statements, 59 | const struct st_location_t *location, 60 | const struct config_iface_t *config, 61 | struct issues_iface_t *issues); 62 | -------------------------------------------------------------------------------- /src/statements/conditionals.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | struct if_statement_t; 27 | 28 | struct if_statement_t * st_create_elsif_clause( 29 | struct expression_iface_t *condition, 30 | const struct st_location_t *condition_location, 31 | struct invoke_iface_t *true_statements, 32 | const struct st_location_t *location, 33 | const struct config_iface_t *config, 34 | struct issues_iface_t *issues); 35 | 36 | struct if_statement_t * st_extend_elsif_clauses( 37 | struct if_statement_t *elsif_clauses, 38 | struct if_statement_t *elsif_clause, 39 | const struct st_location_t *location, 40 | const struct config_iface_t *config, 41 | struct issues_iface_t *issues); 42 | 43 | void st_destroy_elsif_clauses( 44 | struct if_statement_t *clauses); 45 | 46 | struct invoke_iface_t * st_create_if_statement( 47 | struct expression_iface_t *condition, 48 | const struct st_location_t *condition_location, 49 | struct invoke_iface_t *true_statements, 50 | struct if_statement_t *elsif_clauses, 51 | struct invoke_iface_t *else_statements, 52 | const struct st_location_t *location, 53 | const struct config_iface_t *config, 54 | struct issues_iface_t *issues); 55 | -------------------------------------------------------------------------------- /src/statements/empty.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | /**************************************************************************/ 26 | /* Invoke interface */ 27 | /**************************************************************************/ 28 | struct empty_statement_t { 29 | struct invoke_iface_t invoke; 30 | struct st_location_t *location; 31 | }; 32 | 33 | static int empty_statement_verify( 34 | struct invoke_iface_t *self, 35 | const struct config_iface_t *config, 36 | struct issues_iface_t *issues) 37 | { 38 | return ESSTEE_OK; 39 | } 40 | 41 | static int empty_statement_step( 42 | struct invoke_iface_t *self, 43 | struct cursor_iface_t *cursor, 44 | const struct systime_iface_t *time, 45 | const struct config_iface_t *config, 46 | struct issues_iface_t *issues) 47 | { 48 | return INVOKE_RESULT_FINISHED; 49 | } 50 | 51 | static int empty_statement_reset( 52 | struct invoke_iface_t *self, 53 | const struct config_iface_t *config, 54 | struct issues_iface_t *issues) 55 | { 56 | return ESSTEE_OK; 57 | } 58 | 59 | static int empty_statement_post_clone( 60 | struct invoke_iface_t *self, 61 | const struct config_iface_t *config, 62 | struct issues_iface_t *issues) 63 | { 64 | return ESSTEE_OK; 65 | } 66 | 67 | static void empty_statement_destroy( 68 | struct invoke_iface_t *self) 69 | { 70 | /* TODO: destructor */ 71 | } 72 | 73 | static void empty_statement_clone_destroy( 74 | struct invoke_iface_t *self) 75 | { 76 | /* TODO: destructor */ 77 | } 78 | 79 | static struct invoke_iface_t * empty_statement_clone( 80 | struct invoke_iface_t *self, 81 | struct issues_iface_t *issues) 82 | { 83 | struct empty_statement_t *es = 84 | CONTAINER_OF(self, struct empty_statement_t, invoke); 85 | 86 | struct empty_statement_t *copy = NULL; 87 | ALLOC_OR_ERROR_JUMP( 88 | copy, 89 | struct empty_statement_t, 90 | issues, 91 | error_free_resources); 92 | 93 | memcpy(copy, es, sizeof(struct empty_statement_t)); 94 | copy->invoke.destroy = empty_statement_clone_destroy; 95 | 96 | return &(copy->invoke); 97 | 98 | error_free_resources: 99 | return NULL; 100 | } 101 | 102 | /**************************************************************************/ 103 | /* Public interface */ 104 | /**************************************************************************/ 105 | struct invoke_iface_t * st_append_empty_statement( 106 | struct invoke_iface_t *statement_list, 107 | const struct st_location_t *location, 108 | const struct config_iface_t *config, 109 | struct issues_iface_t *issues) 110 | { 111 | struct empty_statement_t *es = NULL; 112 | struct st_location_t *es_location = NULL; 113 | 114 | ALLOC_OR_ERROR_JUMP( 115 | es, 116 | struct empty_statement_t, 117 | issues, 118 | error_free_resources); 119 | 120 | LOCDUP_OR_ERROR_JUMP( 121 | es_location, 122 | location, 123 | issues, 124 | error_free_resources); 125 | 126 | es->location = es_location; 127 | es->invoke.verify = empty_statement_verify; 128 | es->invoke.step = empty_statement_step; 129 | es->invoke.location = es->location; 130 | es->invoke.clone = empty_statement_clone; 131 | es->invoke.post_clone = empty_statement_post_clone; 132 | es->invoke.reset = empty_statement_reset; 133 | es->invoke.destroy = empty_statement_destroy; 134 | 135 | DL_APPEND(statement_list, &(es->invoke)); 136 | return statement_list; 137 | 138 | error_free_resources: 139 | free(es); 140 | free(es_location); 141 | return NULL; 142 | } 143 | -------------------------------------------------------------------------------- /src/statements/empty.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | struct invoke_iface_t * st_append_empty_statement( 25 | struct invoke_iface_t *statement_list, 26 | const struct st_location_t *location, 27 | const struct config_iface_t *config, 28 | struct issues_iface_t *issues); 29 | 30 | -------------------------------------------------------------------------------- /src/statements/iinvoke.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #define INVOKE_RESULT_FINISHED 1 29 | #define INVOKE_RESULT_IN_PROGRESS 2 30 | #define INVOKE_RESULT_ERROR 3 31 | #define INVOKE_RESULT_ALL_FINISHED 4 32 | 33 | struct invoke_iface_t { 34 | 35 | int (*verify)( 36 | struct invoke_iface_t *self, 37 | const struct config_iface_t *config, 38 | struct issues_iface_t *issues); 39 | 40 | int (*step)( 41 | struct invoke_iface_t *self, 42 | struct cursor_iface_t *cursor, 43 | const struct systime_iface_t *time, 44 | const struct config_iface_t *config, 45 | struct issues_iface_t *issues); 46 | 47 | int (*reset)( 48 | struct invoke_iface_t *self, 49 | const struct config_iface_t *config, 50 | struct issues_iface_t *issues); 51 | 52 | int (*allocate)( 53 | struct invoke_iface_t *self, 54 | struct issues_iface_t *issues); 55 | 56 | struct invoke_iface_t * (*clone)( 57 | struct invoke_iface_t *self, 58 | struct issues_iface_t *issues); 59 | 60 | int (*post_clone)( 61 | struct invoke_iface_t *self, 62 | const struct config_iface_t *config, 63 | struct issues_iface_t *issues); 64 | 65 | void (*destroy)( 66 | struct invoke_iface_t *self); 67 | 68 | const struct st_location_t *location; 69 | 70 | /* Invoke lists */ 71 | struct invoke_iface_t *call_stack_prev; 72 | struct invoke_iface_t *call_stack_next; 73 | 74 | struct invoke_iface_t *exit_context_prev; 75 | struct invoke_iface_t *exit_context_next; 76 | 77 | struct invoke_iface_t *return_context_prev; 78 | struct invoke_iface_t *return_context_next; 79 | 80 | struct invoke_iface_t *prev; 81 | struct invoke_iface_t *next; 82 | }; 83 | -------------------------------------------------------------------------------- /src/statements/invoke_statement.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | struct invoke_iface_t * st_create_invoke_statement( 27 | char *identifier, 28 | const struct st_location_t *identifier_location, 29 | struct invoke_parameters_iface_t *invoke_parameters, 30 | const struct st_location_t *location, 31 | struct named_ref_pool_iface_t *var_refs, 32 | struct named_ref_pool_iface_t *function_refs, 33 | const struct config_iface_t *config, 34 | struct issues_iface_t *issues); 35 | -------------------------------------------------------------------------------- /src/statements/loops.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | struct invoke_iface_t * st_create_for_statement( 27 | char *variable_identifier, 28 | const struct st_location_t *identifier_location, 29 | struct expression_iface_t *from, 30 | struct expression_iface_t *to, 31 | struct expression_iface_t *increment, 32 | struct invoke_iface_t *statements, 33 | const struct st_location_t *location, 34 | struct named_ref_pool_iface_t *var_refs, 35 | const struct config_iface_t *config, 36 | struct issues_iface_t *issues); 37 | 38 | struct invoke_iface_t * st_create_while_statement( 39 | struct expression_iface_t *while_expression, 40 | struct invoke_iface_t *statements, 41 | const struct st_location_t *location, 42 | const struct config_iface_t *config, 43 | struct issues_iface_t *issues); 44 | 45 | struct invoke_iface_t * st_create_repeat_statement( 46 | struct expression_iface_t *repeat_expression, 47 | struct invoke_iface_t *statements, 48 | const struct st_location_t *location, 49 | const struct config_iface_t *config, 50 | struct issues_iface_t *issues); 51 | -------------------------------------------------------------------------------- /src/statements/pop_call_stack.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | struct invoke_iface_t * st_create_exit_statement( 23 | const struct st_location_t *location, 24 | const struct config_iface_t *config, 25 | struct issues_iface_t *issues); 26 | 27 | struct invoke_iface_t * st_create_return_statement( 28 | const struct st_location_t *location, 29 | const struct config_iface_t *config, 30 | struct issues_iface_t *issues); 31 | -------------------------------------------------------------------------------- /src/statements/qualified_assignment.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | struct invoke_iface_t * st_create_assignment_statement_qualified( 27 | struct qualified_identifier_iface_t *qualified_identifier, 28 | struct expression_iface_t *assignment, 29 | const struct st_location_t *location, 30 | const struct config_iface_t *config, 31 | struct issues_iface_t *issues); 32 | -------------------------------------------------------------------------------- /src/statements/simple_assignment.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | struct invoke_iface_t * st_create_assignment_statement_simple( 27 | char *identifier, 28 | const struct st_location_t *identifier_location, 29 | struct expression_iface_t *assignment, 30 | const struct st_location_t *location, 31 | struct named_ref_pool_iface_t *var_refs, 32 | const struct config_iface_t *config, 33 | struct issues_iface_t *issues); 34 | -------------------------------------------------------------------------------- /src/statements/statements.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | #include 25 | 26 | 27 | int st_allocate_statements( 28 | struct invoke_iface_t *statements, 29 | struct issues_iface_t *issues) 30 | { 31 | struct invoke_iface_t *itr = NULL; 32 | DL_FOREACH(statements, itr) 33 | { 34 | if(!itr->allocate) 35 | { 36 | continue; 37 | } 38 | 39 | if(itr->allocate(itr, issues) != ESSTEE_OK) 40 | { 41 | return ESSTEE_ERROR; 42 | } 43 | } 44 | 45 | return ESSTEE_OK; 46 | } 47 | 48 | int st_verify_statements( 49 | struct invoke_iface_t *statements, 50 | const struct config_iface_t *config, 51 | struct issues_iface_t *issues) 52 | { 53 | int result = ESSTEE_OK; 54 | struct invoke_iface_t *itr = NULL; 55 | DL_FOREACH(statements, itr) 56 | { 57 | if(itr->verify(itr, config, issues) != ESSTEE_OK) 58 | { 59 | result = ESSTEE_ERROR; 60 | } 61 | } 62 | 63 | return result; 64 | } 65 | 66 | int st_post_clone_hook_for_statements( 67 | struct invoke_iface_t *statements, 68 | const struct config_iface_t *config, 69 | struct issues_iface_t *issues) 70 | { 71 | int result = ESSTEE_OK; 72 | struct invoke_iface_t *itr = NULL; 73 | DL_FOREACH(statements, itr) 74 | { 75 | if(itr->post_clone && itr->post_clone(itr, config, issues) != ESSTEE_OK) 76 | { 77 | result = ESSTEE_ERROR; 78 | } 79 | } 80 | 81 | return result; 82 | } 83 | 84 | 85 | void st_destroy_statements( 86 | struct invoke_iface_t *statements) 87 | { 88 | /* TODO: destroy statements */ 89 | } 90 | -------------------------------------------------------------------------------- /src/statements/statements.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | int st_allocate_statements( 27 | struct invoke_iface_t *statements, 28 | struct issues_iface_t *issues); 29 | 30 | int st_verify_statements( 31 | struct invoke_iface_t *statements, 32 | const struct config_iface_t *config, 33 | struct issues_iface_t *errors); 34 | 35 | int st_post_clone_hook_for_statements( 36 | struct invoke_iface_t *statements, 37 | const struct config_iface_t *config, 38 | struct issues_iface_t *issues); 39 | 40 | void st_destroy_statements( 41 | struct invoke_iface_t *statements); 42 | -------------------------------------------------------------------------------- /src/tests/integration/README.md: -------------------------------------------------------------------------------- 1 | # Running and writing tests 2 | 3 | The simple `runtests.sh` script is designed for running integration 4 | tests, i.e. tests for the complete interpreter chain. The script reads 5 | test definitions from stdin and executes them using the 6 | `program-tester` binary. To run tests, first build the `program-tester` 7 | by issuing (in the root project folder) 8 | 9 | ``` 10 | make program-tester 11 | ``` 12 | 13 | Test defintions can be grouped together in files (like the files found 14 | in the folder of this file), and then executed by 15 | 16 | ``` 17 | cat tests | ./runtests.sh 18 | ``` 19 | 20 | The success or failure of the tests are written to stdout, while any 21 | output from the tests are written to the file `error.output`. Note 22 | that, each test rewrites `error.output`, so it will only contain the 23 | output of the last run test. 24 | 25 | ## Test definition structure 26 | 27 | A test definition consists of six fields separated by '!'. Order and 28 | contents of the fields: 29 | 1. The path to the .ST file which is to be loaded and run 30 | 2. The program in the .ST file that is to be run (the file may contain multiple programs) 31 | 3. The expected output from the `program-tester` binary (1 for error and 0 for success) 32 | 4. The queries that are to be executed in the interpreter before running a cycle of the program 33 | 5. The queries that are to be executed in the interpreter after the cycle has finished 34 | 6. The excepted output from `program-tester`, this will be set by the post-cycle queries 35 | 36 | ### Queries 37 | 38 | Pre- and post-cycle queries are given in ST syntax. Output from 39 | pre-cycle queries is ignored, while the output from the post cycle 40 | queries is checked for equivalence with the expected output. A query 41 | is either a reference to a variable, or an assignment 42 | statement. Multiple queries are separated by ';'. When referring to 43 | variables of a program, enclose the program name in '[]'. The 44 | following would print the value of the variable 'my_var' inside the 45 | function block 'my_fb' part of 'my_prgm', and also set the value of 46 | the global variable 'global_var'. Note that the last query has no 47 | trailing ";". 48 | 49 | ``` 50 | [my_prgm].my_fb.my_var;global_var:=1+2*3 51 | ``` 52 | 53 | ## Options to runtests.sh 54 | 55 | The following options are possible to pass to `runtests.sh`: 56 | 57 | ``` 58 | cat tests | ./runtests.sh [filter] [gdb / bison] 59 | ``` 60 | 61 | The filter option is an awk regex which can limit which tests are run, 62 | i.e. for the test to be run its defintion has to match the filter 63 | regex. 64 | 65 | If a filter is passed, together with "gdb", the `gdb` commands needed 66 | to run the first matched test will be written to 67 | `test.gdb.commands`. This includes setting the binary file and 68 | arguments to the program. To load the test in `gdb`, open up `gdb` and 69 | execute: 70 | 71 | ``` 72 | source test.gdb.commands 73 | ``` 74 | 75 | If a filter is passed, together with "bison", the output in 76 | `error.output` will include bison debug information. 77 | -------------------------------------------------------------------------------- /src/tests/integration/arrays.tests: -------------------------------------------------------------------------------- 1 | arrays.ST!t!0!none!none! 2 | arrays.ST!t!1!none!arr1[1]! 3 | arrays.ST!t!1!none!arr1[7]! 4 | arrays.ST!t!0!none!arr4[1,1,1];arr4[2,1,1];arr4[1,4,3];arr4[2,4,3]!1;21;12;39 5 | arrays.ST!t!0!none!arr1![0,0,0,0,0] 6 | arrays.ST!t!0!none!arr1[5]:=999;arr1!999;[0,0,0,999,0] 7 | -------------------------------------------------------------------------------- /src/tests/integration/builtins.tests: -------------------------------------------------------------------------------- 1 | builtins/cast.ST!t!0!none![t].b!true 2 | -------------------------------------------------------------------------------- /src/tests/integration/conditionals.tests: -------------------------------------------------------------------------------- 1 | conditionals.ST!t_if!0![t_if].i1:=1![t_if].i2!10 2 | conditionals.ST!t_if!0![t_if].i1:=2![t_if].i2!20 3 | conditionals.ST!t_if!0![t_if].i1:=3![t_if].i2!30 4 | conditionals.ST!t_if!0![t_if].i1:=9![t_if].i2!40 5 | conditionals.ST!t_if_simple!0![t_if_simple].i1:=1![t_if_simple].i2!10 6 | conditionals.ST!t_if_simple!0![t_if_simple].i1:=0![t_if_simple].i2!20 7 | conditionals.ST!t_case!0![t_case].i1:=1![t_case].i2!10 8 | conditionals.ST!t_case!0![t_case].i1:=2![t_case].i2!20 9 | conditionals.ST!t_case!0![t_case].i1:=3![t_case].i2!30 10 | conditionals.ST!t_case!0![t_case].i1:=9![t_case].i2!40 11 | -------------------------------------------------------------------------------- /src/tests/integration/derived_types.tests: -------------------------------------------------------------------------------- 1 | derived_types/basic.ST!t!0!none!v1;v2;v3;v4!1;5;5;0 2 | derived_types/basic.ST!t!0!none!v1:=v3!5 3 | derived_types/basic.ST!t!0!none!v5!1 4 | derived_types/circularrefs.ST!t!1!none!none! 5 | -------------------------------------------------------------------------------- /src/tests/integration/direct_memory.tests: -------------------------------------------------------------------------------- 1 | directmemory.ST!t!0![t].b1:=true![t].s1;[t].i1;[t].d1;[t].l1!1;1;1;1 2 | directmemory.ST!t!0![t].b8:=true![t].s1;[t].i1;[t].d1;[t].l1!128;128;128;128 3 | directmemory.ST!t!0![t].s1:=255![t].b1;[t].b2;[t].b3;[t].b4;[t].b5;[t].b6;[t].b7;[t].b8!true;true;true;true;true;true;true;true 4 | directmemory.ST!t!0![t].b18:=true![t].s1;[t].s2!0;128 5 | directmemory.ST!t!0![t].s3:=255;[t].s4:=255![t].b1;[t].b2;[t].b11;[t].b12;[t].b8;[t].b18!false;false;false;false;false;false 6 | directmemory.ST!t!0![t].s1:=255;[t].s2:=255![t].i1;[t].i2!65535;0 7 | directmemory.ST!t!0![t].i1:=65535;[t].i2:=65535![t].d1;[t].d2!4294967295;0 8 | # directmemory.ST!t!0![t].d1:=4294967295;[t].d2:=4294967295![t].l1!18446744073709551616 9 | -------------------------------------------------------------------------------- /src/tests/integration/enum.tests: -------------------------------------------------------------------------------- 1 | enum.ST!t!0!none!e;d!one;single 2 | enum.ST!t!0!none!e:=two;d:=single!two;single 3 | enum.ST!t!0!none!e:=three!three 4 | enum.ST!t!1!none!e:=error! 5 | enum.ST!t!1!none!d:=something! 6 | -------------------------------------------------------------------------------- /src/tests/integration/expressions.tests: -------------------------------------------------------------------------------- 1 | literals.ST!t!0!none![t].i1:=1+2!3 2 | literals.ST!t!0!none![t].i1:=2-1!1 3 | literals.ST!t!0!none![t].i1:=1-2!-1 4 | literals.ST!t!0!none![t].i1:=1/1!1 5 | literals.ST!t!1!none![t].i1:=1/0!none 6 | literals.ST!t!0!none![t].i1:=4*2!8 7 | literals.ST!t!0!none![t].i1:=2*3+1!7 8 | literals.ST!t!0!none![t].i1:=2*(3+1)!8 9 | literals.ST!t!0!none![t].i1:=(1)+(2)!3 10 | literals.ST!t!0!none![t].i1:=10+4/2!12 11 | literals.ST!t!0!none![t].i1:=(10+4)/2!7 12 | literals.ST!t!0!none![t].i1:=-1+1!0 13 | literals.ST!t!0!none![t].i1:=-1*-1!1 14 | literals.ST!t!0!none![t].i1:=-1/-1!1 15 | literals.ST!t!0!none![t].i1:=-(1+2)!-3 16 | literals.ST!t!0!none![t].i1:=-(-(1+1))!2 17 | literals.ST!t!0!none![t].r1:=1.0+1.5!2.50 18 | literals.ST!t!0!none![t].b1:=true and false!false 19 | literals.ST!t!0!none![t].b1:=true or false!true 20 | literals.ST!t!0!none![t].b1:=(true or false) and false!false 21 | literals.ST!t!0!none![t].b1:=((true or false) and false) or true!true 22 | literals.ST!t!0!none![t].b1:=not true!false 23 | literals.ST!t!0!none![t].b1:=not false!true 24 | -------------------------------------------------------------------------------- /src/tests/integration/function_blocks.tests: -------------------------------------------------------------------------------- 1 | function_blocks/simple.ST!t!0![t].a:=1;[t].b:=1![t].simple.out;[t].simple.last;[t].simple.in!1;0;1 2 | function_blocks/simple.ST!t!0![t].a:=1;[t].b:=2![t].simple.out;[t].simple.last;[t].simple.in!2;1;1 3 | function_blocks/simple.ST!no_args!0!none![no_args].simple.out;[no_args].simple.last;[no_args].simple.in!0;0;0 4 | function_blocks/simple.ST!bad_in_type!1!none!none! 5 | function_blocks/noninput.ST!bad_non_input!1!none!none! 6 | function_blocks/toomany.ST!bad_too_many!1!none!none! 7 | function_blocks/circular_ref.ST!t!1!none!none 8 | function_blocks/circular_ref_2.ST!t!1!none!none 9 | function_blocks/circular_ref_3.ST!t!1!none!none 10 | function_blocks/circular_ref_4.ST!t!1!none!none 11 | function_blocks/circular_ref_5.ST!t!1!none!none 12 | function_blocks/circular_ref_6.ST!t!1!none!none 13 | function_blocks/simple_assignment.ST!t!0!none![t].a0.out;[t].a1.out;[t].a2.out;[t].a3.out;[t2].a1.out!0;10;20;0;0 14 | function_blocks/qualified_assignment.ST!t!0!none![t].t1.a;[t].t1.b;[t].t2.a;[t].t2.b![100,0,0,0,0];[0,200,0,0,0];[0,0,0,0,500];[0,0,300,0,0] 15 | function_blocks/qualified_assignment.ST!tnest!0!none![tnest].t.t1.a;[tnest].t.t1.b![100,0,0,0,0];[0,200,0,0,0] 16 | function_blocks/invoke.ST!t!0!none![t].fb.a;[t].fb.b;[t].fb.c!1;2;3 17 | function_blocks/conditionals.ST!t_if!0![t_if].fb.i1:=1![t_if].fb.i2!10 18 | function_blocks/conditionals.ST!t_if!0![t_if].fb.i1:=2![t_if].fb.i2!20 19 | function_blocks/conditionals.ST!t_if!0![t_if].fb.i1:=3![t_if].fb.i2!30 20 | function_blocks/conditionals.ST!t_if!0![t_if].fb.i1:=9![t_if].fb.i2!40 21 | function_blocks/conditionals.ST!t_case!0![t_case].fb.i1:=1![t_case].fb.i2!10 22 | function_blocks/conditionals.ST!t_case!0![t_case].fb.i1:=2![t_case].fb.i2!20 23 | function_blocks/conditionals.ST!t_case!0![t_case].fb.i1:=3![t_case].fb.i2!30 24 | function_blocks/conditionals.ST!t_case!0![t_case].fb.i1:=9![t_case].fb.i2!40 25 | function_blocks/loops.ST!t_for!0!none![t_for].fb.out![1,2,3,4,5] 26 | function_blocks/loops.ST!t_for!0!none![t_for].fb.out2![2,4,6,8,10] 27 | function_blocks/loops.ST!t_while!0!none![t_while].fb.itr;[t_while].fb.control;[t_while].fb.control_two;[t_while].fb.itr_two!6;5;0;4 28 | function_blocks/loops.ST!t_repeat!0!none![t_repeat].fb.itr;[t_repeat].fb.control;[t_repeat].fb.control_two;[t_repeat].fb.itr_two!6;5;1;5 29 | -------------------------------------------------------------------------------- /src/tests/integration/functions.tests: -------------------------------------------------------------------------------- 1 | function/min.ST!t!0![t].a:=1;[t].b:=-1![t].c;[t].d!-1;-1 2 | function/badinput.ST!t!1!none!none! 3 | function/badtoomany.ST!t!1!none!none! 4 | function/badnotin.ST!t!1!none!none! 5 | function/disjointin.ST!t!0![t].a:=10;[t].b:=4![t].c;[t].d!6;6 6 | function/reset.ST!t!0!none![t].c;[t].d!30;0 7 | function/funcparams.ST!t!0![t].a:=10![t].c;[t].d!47;110 8 | -------------------------------------------------------------------------------- /src/tests/integration/literals.tests: -------------------------------------------------------------------------------- 1 | literals.ST!t!0!none![t].i1:=1;[t].i2:=2#1;[t].i3:=8#1;[t].i4:=16#1!1;1;1;1 2 | literals.ST!t!0!none![t].i1:=1_0_0_0;[t].i2:=2#0100;[t].i3:=8#10;[t].i4:=16#ff!1000;4;8;255 3 | literals.ST!t!0!none![t].i1:=12345;[t].i2:=12345;[t].i3:=22345__;[t].i4:=3_2_3__99_!12345;12345;22345;32399 4 | literals.ST!t!0!none![t].i1:=2#1110;[t].i2:=2#0_00_1__11__00_!14;28 5 | literals.ST!t!0!none![t].i1:=8#0_71_2;[t].i2:=8#333__!458;219 6 | literals.ST!t!0!none![t].i1:=16#01;[t].i2:=16#aa_aa___bb!1;11184827 7 | literals.ST!t!0!none![t].r1:=1.0;[t].r2:=2.0!1.00;2.00 8 | literals.ST!t!0!none![t].r1:=1.0e1;[t].r2:=2.0e1!10.00;20.00 9 | literals.ST!t!1!none![t].r1:=1.0e1.0!none 10 | literals.ST!t!0!none![t].b1:=true;[t].b2:=false!true;false 11 | literals.ST!t!0!none![t].b1:=TRUE;[t].b2:=FALSE!true;false 12 | literals.ST!t!0!none![t].b1:=tRuE;[t].b2:=fAlSe!true;false 13 | literals.ST!t!0!none![t].t1:=T#10s!0.00d0.00h0.00m10.00s0.00ms 14 | literals.ST!t!0!none![t].t1:=T#200s!0.00d0.00h0.00m200.00s0.00ms 15 | literals.ST!t!0!none![t].t1:=T#2.4s!0.00d0.00h0.00m2.40s0.00ms 16 | literals.ST!t!1!none![t].t1:=T#2.4s0.03ms!none 17 | literals.ST!t!0!none![t].td:=TOD#10:43:10.10!10h43m10.10s 18 | literals.ST!t!0!none![t].td:=TIME_OF_DAY#09:01:01.01!9h1m1.01s 19 | literals.ST!t!1!none![t].td:=TOD#24:00:00.00!none 20 | literals.ST!t!1!none![t].td:=TOD#00:60:00.00!none 21 | literals.ST!t!1!none![t].td:=TOD#00:00:60.00!none 22 | literals.ST!t!0!none![t].td:=TOD#00:00:00.99!0h0m0.99s 23 | literals.ST!t!0!none![t].d1:=DATE#2021-01-02!2021-01-02 24 | literals.ST!t!0!none![t].d1:=DATE#0000-01-01!0000-01-01 25 | literals.ST!t!1!none![t].d1:=DATE#0000-13-01!none 26 | literals.ST!t!1!none![t].d1:=DATE#0000-01-32!none 27 | literals.ST!t!0!none![t].dd:=DT#0000-01-01-10:11:50.50!0000-01-01-10h11m50.50s 28 | literals.ST!t!0!none![t].str:='hello'!'hello' 29 | literals.ST!t!0!none![t].str:=''!'' 30 | literals.ST!t!1!none![t].str:="hello"!none 31 | literals.ST!t!1!none![t].wstr:='hello'!none 32 | literals.ST!t!0!none![t].wstr:="hello"!"hello" 33 | literals.ST!t!0!none![t].wstr:=""!"" 34 | literals.ST!t_init!0!none![t_init].i1;[t_init].i2;[t_init].i3;[t_init].i4;[t_init].r1;[t_init].r2!1;2;3;4;1.00;2.00 35 | literals.ST!t_init!0!none![t_init].t1;[t_init].b1;[t_init].b2!0.00d0.00h0.00m1.00s0.00ms;true;false 36 | literals.ST!t_init!0!none![t_init].td;[t_init].d1;[t_init].dd!10h10m10.10s;1234-01-02;1234-01-01-10h10m10.10s 37 | literals.ST!t_init!0!none![t_init].str;[t_init].wstr!'single';"double" 38 | -------------------------------------------------------------------------------- /src/tests/integration/loops.tests: -------------------------------------------------------------------------------- 1 | loops/for.ST!t!0!none![t].out![1,2,3,4,5] 2 | loops/for.ST!t!0!none![t].out2![2,4,6,8,10] 3 | loops/forrange.ST!t!0![t].from_value:=1;[t].to_value:=5![t].sum!15 4 | loops/forrange.ST!t!0![t].from_value:=5;[t].to_value:=1![t].sum!0 5 | loops/forrange.ST!t!0![t].from_value:=1+0;[t].to_value:=2*2+1![t].sum!15 6 | loops/forexit.ST!t!0!none![t].out![1,2,0,0,0] 7 | loops/while.ST!t!0!none![t].itr;[t].control;[t].control_two;[t].itr_two!6;5;0;4 8 | loops/whilenotbool.ST!t!1!none!none! 9 | loops/repeat.ST!t!0!none![t].itr;[t].control;[t].control_two;[t].itr_two!6;5;1;5 10 | loops/repeatnotbool.ST!t!1!none!none! 11 | -------------------------------------------------------------------------------- /src/tests/integration/runtests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | RUNNER=../../../build/program-tester 4 | 5 | IFS="!" 6 | 7 | while read FILE PROGRAM EXIT_STATUS PRE_QUERIES POST_QUERIES EXPECTED 8 | do 9 | if [[ "$FILE" =~ \# ]] 10 | then 11 | continue 12 | fi 13 | 14 | if [ -n "$1" ] 15 | then 16 | DO_TEST=`echo $FILE $PROGRAM $EXIT_STATUS $PRE_QUERIES $POST_QUERIES $EXPECTED | awk "/$1/"` 17 | 18 | if [ -z "$DO_TEST" ] 19 | then 20 | continue 21 | fi 22 | fi 23 | 24 | PRE_ARGS="" 25 | if [ ! "$PRE_QUERIES" = "none" ] 26 | then 27 | if [[ $PRE_QUERIES =~ \' ]] 28 | then 29 | PRE_DELIM='"' 30 | else 31 | PRE_DELIM="'" 32 | fi 33 | 34 | PRE_ARGS="--quiet-pre-run --pre-run-queries=$PRE_DELIM$PRE_QUERIES$PRE_DELIM" 35 | fi 36 | 37 | POST_ARGS="" 38 | if [ ! "$POST_QUERIES" = "none" ] 39 | then 40 | if [[ $POST_QUERIES =~ \' ]] 41 | then 42 | POST_DELIM='"' 43 | else 44 | POST_DELIM="'" 45 | fi 46 | 47 | POST_ARGS="--post-run-queries=$POST_DELIM$POST_QUERIES$POST_DELIM" 48 | fi 49 | 50 | if [ "$2" == "gdb" ] 51 | then 52 | echo "Writing GDB debug commands..." 53 | echo file $RUNNER > test.gdb.commands 54 | echo set args --file="../programs/$FILE" --program="$PROGRAM" $PRE_ARGS $POST_ARGS >> test.gdb.commands 55 | break 56 | fi 57 | 58 | BISON_CMD="" 59 | if [ "$2" == "bison" ] 60 | then 61 | BISON_CMD="--bison-debug" 62 | fi 63 | 64 | TEST_CMD="$RUNNER --file='"../programs/$FILE"' --program='"$PROGRAM"' "$PRE_ARGS" "$POST_ARGS" "$BISON_CMD" 2>error.output" 65 | 66 | if [ -n "$1" ] 67 | then 68 | printf "Testing\n" 69 | printf "$TEST_CMD\n" 70 | fi 71 | 72 | OUT=$(eval $TEST_CMD) 73 | 74 | TEST_STATUS=$? 75 | 76 | TEST_FAILED="no" 77 | if [ ! "$TEST_STATUS" = "$EXIT_STATUS" ] 78 | then 79 | TEST_FAILED="yes" 80 | fi 81 | 82 | if [ "$EXPECTED" = "none" ] 83 | then 84 | if [ -n "$OUT" ] 85 | then 86 | TEST_FAILED="yes" 87 | fi 88 | else 89 | if [ ! "$OUT" = "$EXPECTED" ] 90 | then 91 | TEST_FAILED="yes" 92 | else 93 | TEST_PASSED="yes" 94 | fi 95 | fi 96 | 97 | if [ "$TEST_FAILED" = "yes" ] 98 | then 99 | printf "############################################\n" 100 | printf "Test failed!\n" 101 | printf " exit status\t\t%d\n" $TEST_STATUS 102 | printf " expected exit\t\t%d\n" $EXIT_STATUS 103 | printf " pre queries\t\t%s\n" $PRE_QUERIES 104 | printf " post queries\t\t%s\n" $POST_QUERIES 105 | printf " test output\t\t%s\n" $OUT 106 | printf " expected\t\t%s\n" $EXPECTED 107 | 108 | SOME_TEST_FAILED="yes" 109 | elif [ -n "$1" ] 110 | then 111 | printf " exit status\t\t%d\n" $TEST_STATUS 112 | printf " expected exit\t\t%d\n" $EXIT_STATUS 113 | printf " pre queries\t\t%s\n" $PRE_QUERIES 114 | printf " post queries\t\t%s\n" $POST_QUERIES 115 | printf " test output\t\t%s\n" $OUT 116 | printf " expected\t\t%s\n" $EXPECTED 117 | fi 118 | done 119 | 120 | if [ -z "$SOME_TEST_FAILED" -a -n "$TEST_PASSED" ] 121 | then 122 | echo "All tests passed!" 123 | else 124 | exit 1 125 | fi 126 | -------------------------------------------------------------------------------- /src/tests/integration/subrange.tests: -------------------------------------------------------------------------------- 1 | subrange/basic.ST!t!0!none!sr;sr_default;sr_one!-10;2;1 2 | subrange/basic.ST!t!0!none!sr:=-10!-10 3 | subrange/basic.ST!t!0!none!sr:=2!2 4 | subrange/basic.ST!t!0!none!sr:=0!0 5 | subrange/basic.ST!t!1!none!sr:=-11! 6 | subrange/basic.ST!t!1!none!sr:=3! 7 | subrange/basic.ST!t!0!none!sr_default!2 8 | subrange/basic.ST!t!0!none!sr_one!1 9 | subrange/basic.ST!t!0!none!sr_one:=1!1 10 | subrange/badrange.ST!t!1!none!none 11 | -------------------------------------------------------------------------------- /src/tests/programs/arrays.ST: -------------------------------------------------------------------------------- 1 | VAR_GLOBAL 2 | arr1 : ARRAY [2..6] of INT; 3 | arr2 : ARRAY [-10..0] of INT; 4 | arr3 : ARRAY [0..1,0..2,0..3] of INT; 5 | arr4 : ARRAY [1..2,1..4,1..3] of INT := 6 | [ 7 | [[1,2,3],[4,5,6],[7,8,9],[10,11,12]], 8 | [[21,22,23],[31,32,33],[34,35,36],[37,38,39]] 9 | ]; 10 | END_VAR 11 | 12 | PROGRAM t 13 | 14 | ; 15 | 16 | END_PROGRAM 17 | -------------------------------------------------------------------------------- /src/tests/programs/builtins/cast.ST: -------------------------------------------------------------------------------- 1 | PROGRAM t 2 | 3 | VAR 4 | b : BOOL; 5 | si : SINT; 6 | i : INT; 7 | di : DINT; 8 | usi : USINT; 9 | ui : UINT; 10 | udi : UDINT; 11 | END_VAR 12 | 13 | b := USINT_TO_BOOL(100); 14 | 15 | END_PROGRAM -------------------------------------------------------------------------------- /src/tests/programs/conditionals.ST: -------------------------------------------------------------------------------- 1 | PROGRAM t_if 2 | 3 | VAR 4 | i1 : DINT; 5 | i2 : DINT; 6 | END_VAR 7 | 8 | if i1 = 1 then 9 | i2 := 10; 10 | elsif i1 = 2 then 11 | i2 := 20; 12 | elsif i1 = 3 then 13 | i2 := 30; 14 | else 15 | i2 := 40; 16 | end_if; 17 | 18 | END_PROGRAM 19 | 20 | PROGRAM t_if_simple 21 | 22 | VAR 23 | i1 : DINT; 24 | i2 : DINT := 20; 25 | END_VAR 26 | 27 | if i1 = 1 then 28 | i2 := 10; 29 | end_if; 30 | 31 | END_PROGRAM 32 | 33 | 34 | PROGRAM t_case 35 | 36 | VAR 37 | i1 : DINT; 38 | i2 : DINT; 39 | END_VAR 40 | 41 | case i1 of 42 | 43 | 1: i2 := 10; 44 | 45 | 2: i2 := 20; 46 | 47 | 3: i2 := 30; 48 | 49 | else i2 := 40; 50 | 51 | end_case; 52 | 53 | END_PROGRAM 54 | 55 | -------------------------------------------------------------------------------- /src/tests/programs/derived_types/basic.ST: -------------------------------------------------------------------------------- 1 | TYPE 2 | base_type : INT; 3 | t1 : base_type; 4 | t2 : t1 := 1; 5 | t3 : t2; 6 | 7 | t4 : INT := 5; 8 | t5 : t3 := 5; 9 | END_TYPE 10 | 11 | VAR_GLOBAL 12 | v1 : t3; 13 | v2 : t4; 14 | v3 : t5; 15 | v4 : t1; 16 | v5 : later_defined; 17 | END_VAR 18 | 19 | TYPE 20 | later_defined : t2; 21 | END_TYPE 22 | 23 | PROGRAM t 24 | 25 | ; 26 | 27 | END_PROGRAM 28 | -------------------------------------------------------------------------------- /src/tests/programs/derived_types/circularrefs.ST: -------------------------------------------------------------------------------- 1 | PROGRAM t 2 | 3 | VAR 4 | itr : INT; 5 | v3 : INT := 0; 6 | END_VAR 7 | 8 | for itr := 1 to 5 DO 9 | v3 := to 10 | 11 | END_PROGRAM 12 | -------------------------------------------------------------------------------- /src/tests/programs/directmemory.ST: -------------------------------------------------------------------------------- 1 | PROGRAM t 2 | 3 | VAR 4 | b1 AT %MX0.0 : BOOL; 5 | b2 AT %MX0.1 : BOOL; 6 | b3 AT %MX0.2 : BOOL; 7 | b4 AT %MX0.3 : BOOL; 8 | b5 AT %MX0.4 : BOOL; 9 | b6 AT %MX0.5 : BOOL; 10 | b7 AT %MX0.6 : BOOL; 11 | b8 AT %MX0.7 : BOOL; 12 | 13 | b11 AT %MX1.0 : BOOL; 14 | b12 AT %MX1.1 : BOOL; 15 | b13 AT %MX1.2 : BOOL; 16 | b14 AT %MX1.3 : BOOL; 17 | b15 AT %MX1.4 : BOOL; 18 | b16 AT %MX1.5 : BOOL; 19 | b17 AT %MX1.6 : BOOL; 20 | b18 AT %MX1.7 : BOOL; 21 | 22 | s1 AT %MB0 : USINT; 23 | s2 AT %MB1 : USINT; 24 | s3 AT %MB2 : USINT; 25 | s4 AT %MB3 : USINT; 26 | s5 AT %MB4 : USINT; 27 | s6 AT %MB5 : USINT; 28 | s7 AT %MB6 : USINT; 29 | s8 AT %MB7 : USINT; 30 | 31 | i1 AT %MW0 : UINT; 32 | i2 AT %MW1 : UINT; 33 | i3 AT %MW2 : UINT; 34 | i4 AT %MW3 : UINT; 35 | 36 | d1 AT %MD0 : UDINT; 37 | d2 AT %MD1 : UDINT; 38 | 39 | l1 AT %ML0 : ULINT; 40 | END_VAR 41 | 42 | ; 43 | 44 | END_PROGRAM 45 | -------------------------------------------------------------------------------- /src/tests/programs/enum.ST: -------------------------------------------------------------------------------- 1 | VAR_GLOBAL 2 | e : (one, two, three); 3 | d : (single); 4 | END_VAR 5 | 6 | PROGRAM t 7 | 8 | ; 9 | 10 | END_PROGRAM 11 | -------------------------------------------------------------------------------- /src/tests/programs/example.ST: -------------------------------------------------------------------------------- 1 | PROGRAM testprgm 2 | 3 | VAR 4 | i: INT; 5 | a: UINT; 6 | END_VAR 7 | 8 | FOR i := 1 TO 20 DO 9 | 10 | IF i > 10 THEN 11 | a := 99; 12 | ELSE 13 | 14 | a := 10 - i; 15 | 16 | END_IF; 17 | 18 | END_FOR; 19 | 20 | 21 | END_PROGRAM -------------------------------------------------------------------------------- /src/tests/programs/function/badinput.ST: -------------------------------------------------------------------------------- 1 | FUNCTION my_func : INT 2 | 3 | VAR 4 | not_in : INT; 5 | END_VAR 6 | 7 | VAR_INPUT 8 | in1 : INT; 9 | in2 : INT; 10 | END_VAR 11 | 12 | ; 13 | 14 | END_FUNCTION 15 | 16 | PROGRAM t 17 | 18 | VAR 19 | a : INT; 20 | b : INT; 21 | c : INT; 22 | d : INT; 23 | END_VAR 24 | 25 | c := my_func("wrong_type", in2:=false); 26 | 27 | END_PROGRAM -------------------------------------------------------------------------------- /src/tests/programs/function/badinputname.ST: -------------------------------------------------------------------------------- 1 | FUNCTION my_func : INT 2 | 3 | VAR 4 | not_in : INT; 5 | END_VAR 6 | 7 | VAR_INPUT 8 | in1 : INT; 9 | in2 : INT; 10 | END_VAR 11 | 12 | ; 13 | 14 | END_FUNCTION 15 | 16 | PROGRAM t 17 | 18 | VAR 19 | a : INT; 20 | b : INT; 21 | c : INT; 22 | d : INT; 23 | END_VAR 24 | 25 | c := my_func(bad=1); 26 | 27 | END_PROGRAM -------------------------------------------------------------------------------- /src/tests/programs/function/badnotin.ST: -------------------------------------------------------------------------------- 1 | FUNCTION my_func : INT 2 | 3 | VAR 4 | not_in : INT; 5 | END_VAR 6 | 7 | VAR_INPUT 8 | in1 : INT; 9 | in2 : INT; 10 | END_VAR 11 | 12 | ; 13 | 14 | END_FUNCTION 15 | 16 | PROGRAM t 17 | 18 | VAR 19 | a : INT; 20 | b : INT; 21 | c : INT; 22 | d : INT; 23 | END_VAR 24 | 25 | c := my_func(not_in:=1); 26 | 27 | END_PROGRAM -------------------------------------------------------------------------------- /src/tests/programs/function/badtoomany.ST: -------------------------------------------------------------------------------- 1 | FUNCTION my_func : INT 2 | 3 | VAR 4 | not_in : INT; 5 | END_VAR 6 | 7 | VAR_INPUT 8 | in1 : INT; 9 | in2 : INT; 10 | END_VAR 11 | 12 | ; 13 | 14 | END_FUNCTION 15 | 16 | PROGRAM t 17 | 18 | VAR 19 | a : INT; 20 | b : INT; 21 | c : INT; 22 | d : INT; 23 | END_VAR 24 | 25 | c := my_func(1, 2, 3); 26 | 27 | END_PROGRAM -------------------------------------------------------------------------------- /src/tests/programs/function/disjointin.ST: -------------------------------------------------------------------------------- 1 | FUNCTION my_func : INT 2 | 3 | VAR 4 | not_in : INT; 5 | END_VAR 6 | 7 | VAR_INPUT 8 | in1 : INT; 9 | END_VAR 10 | 11 | VAR 12 | a : INT; 13 | END_VAR 14 | 15 | VAR_INPUT 16 | in2 : INT; 17 | END_VAR 18 | 19 | my_func := in1 - in2; 20 | 21 | END_FUNCTION 22 | 23 | PROGRAM t 24 | 25 | VAR 26 | a : INT; 27 | b : INT; 28 | c : INT; 29 | d : INT; 30 | END_VAR 31 | 32 | c := my_func(a,b); 33 | 34 | d := my_func(in1:=a,in2:=b); 35 | 36 | END_PROGRAM -------------------------------------------------------------------------------- /src/tests/programs/function/funcparams.ST: -------------------------------------------------------------------------------- 1 | FUNCTION my_func : INT 2 | 3 | VAR_INPUT 4 | in1 : INT; 5 | in2 : INT; 6 | END_VAR 7 | 8 | my_func := in1 + in2; 9 | 10 | END_FUNCTION 11 | 12 | PROGRAM t 13 | 14 | VAR 15 | a : INT; 16 | b : INT; 17 | c : INT; 18 | d : INT; 19 | END_VAR 20 | 21 | c := my_func(1+1, my_func(4*10, 5)); 22 | 23 | d := my_func(a, a*10); 24 | 25 | END_PROGRAM -------------------------------------------------------------------------------- /src/tests/programs/function/min.ST: -------------------------------------------------------------------------------- 1 | FUNCTION my_min : INT 2 | 3 | VAR_INPUT 4 | val1 : INT; 5 | val2 : INT; 6 | END_VAR 7 | 8 | if val1 < val2 then 9 | my_min := val1; 10 | else 11 | my_min := val2; 12 | end_if; 13 | 14 | END_FUNCTION 15 | 16 | PROGRAM t 17 | 18 | VAR 19 | a : INT; 20 | b : INT; 21 | c : INT; 22 | d : INT; 23 | END_VAR 24 | 25 | c := my_min(a, b); 26 | 27 | d := my_min(b, a); 28 | 29 | END_PROGRAM -------------------------------------------------------------------------------- /src/tests/programs/function/recursion.ST: -------------------------------------------------------------------------------- 1 | FUNCTION my_func : INT 2 | 3 | VAR_INPUT 4 | in1 : INT; 5 | in2 : INT; 6 | END_VAR 7 | 8 | my_func := in1 + in2; 9 | 10 | END_FUNCTION 11 | 12 | PROGRAM t 13 | 14 | VAR 15 | a : INT; 16 | b : INT; 17 | c : INT; 18 | d : INT; 19 | END_VAR 20 | 21 | c := my_func(my_func(4,5),1+1); 22 | 23 | d := my_func(a, 10*a); 24 | 25 | END_PROGRAM -------------------------------------------------------------------------------- /src/tests/programs/function/reset.ST: -------------------------------------------------------------------------------- 1 | FUNCTION my_func : INT 2 | 3 | VAR 4 | not_in : INT; 5 | END_VAR 6 | 7 | VAR_INPUT 8 | in1 : INT; 9 | in2 : INT; 10 | END_VAR 11 | 12 | my_func := in1 + in2; 13 | 14 | END_FUNCTION 15 | 16 | PROGRAM t 17 | 18 | VAR 19 | a : INT; 20 | b : INT; 21 | c : INT; 22 | d : INT; 23 | END_VAR 24 | 25 | c := my_func(10,20); 26 | 27 | d := my_func(); 28 | 29 | END_PROGRAM -------------------------------------------------------------------------------- /src/tests/programs/function_blocks/circular_ref.ST: -------------------------------------------------------------------------------- 1 | FUNCTION_BLOCK fb_s 2 | 3 | VAR 4 | myself : fb_s; 5 | END_VAR 6 | 7 | ; 8 | 9 | END_FUNCTION_BLOCK 10 | 11 | PROGRAM t 12 | 13 | ; 14 | 15 | END_PROGRAM -------------------------------------------------------------------------------- /src/tests/programs/function_blocks/circular_ref_2.ST: -------------------------------------------------------------------------------- 1 | FUNCTION_BLOCK fb_1_s 2 | 3 | VAR 4 | other_fb : fb_2_s; 5 | END_VAR 6 | 7 | ; 8 | 9 | END_FUNCTION_BLOCK 10 | 11 | FUNCTION_BLOCK fb_2_s 12 | 13 | VAR 14 | the_other_fb : fb_1_s; 15 | END_VAR 16 | 17 | ; 18 | 19 | END_FUNCTION_BLOCK 20 | 21 | PROGRAM t 22 | 23 | ; 24 | 25 | END_PROGRAM -------------------------------------------------------------------------------- /src/tests/programs/function_blocks/circular_ref_3.ST: -------------------------------------------------------------------------------- 1 | 2 | FUNCTION_BLOCK fb_1 3 | 4 | VAR 5 | var_fb_1 : fb_2; 6 | END_VAR 7 | 8 | ; 9 | 10 | END_FUNCTION_BLOCK 11 | 12 | FUNCTION_BLOCK fb_2 13 | 14 | VAR 15 | var_fb_2 : fb_3; 16 | END_VAR 17 | 18 | ; 19 | 20 | END_FUNCTION_BLOCK 21 | 22 | FUNCTION_BLOCK fb_3 23 | 24 | VAR 25 | var_fb_3 : fb_1; 26 | END_VAR 27 | 28 | ; 29 | 30 | END_FUNCTION_BLOCK 31 | 32 | PROGRAM t 33 | 34 | ; 35 | 36 | END_PROGRAM -------------------------------------------------------------------------------- /src/tests/programs/function_blocks/circular_ref_4.ST: -------------------------------------------------------------------------------- 1 | TYPE 2 | d1 : fb_1; 3 | d2 : fb_2; 4 | d3 : fb_3; 5 | END_TYPE 6 | 7 | FUNCTION_BLOCK fb_1 8 | 9 | VAR 10 | var_fb_1 : d1; 11 | END_VAR 12 | 13 | ; 14 | 15 | END_FUNCTION_BLOCK 16 | 17 | FUNCTION_BLOCK fb_2 18 | 19 | VAR 20 | var_fb_2 : d2; 21 | END_VAR 22 | 23 | ; 24 | 25 | END_FUNCTION_BLOCK 26 | 27 | FUNCTION_BLOCK fb_3 28 | 29 | VAR 30 | var_fb_3 : d3; 31 | END_VAR 32 | 33 | ; 34 | 35 | END_FUNCTION_BLOCK 36 | 37 | PROGRAM t 38 | 39 | ; 40 | 41 | END_PROGRAM -------------------------------------------------------------------------------- /src/tests/programs/function_blocks/circular_ref_5.ST: -------------------------------------------------------------------------------- 1 | TYPE 2 | d1 : fb_1; 3 | d2 : d3; 4 | d3 : d1; 5 | END_TYPE 6 | 7 | FUNCTION_BLOCK fb_1 8 | 9 | VAR 10 | var_fb_1 : d1; 11 | END_VAR 12 | 13 | ; 14 | 15 | END_FUNCTION_BLOCK 16 | 17 | FUNCTION_BLOCK fb_2 18 | 19 | VAR 20 | var_fb_2 : d2; 21 | END_VAR 22 | 23 | ; 24 | 25 | END_FUNCTION_BLOCK 26 | 27 | FUNCTION_BLOCK fb_3 28 | 29 | VAR 30 | var_fb_3 : d3; 31 | END_VAR 32 | 33 | ; 34 | 35 | END_FUNCTION_BLOCK 36 | 37 | PROGRAM t 38 | 39 | ; 40 | 41 | END_PROGRAM -------------------------------------------------------------------------------- /src/tests/programs/function_blocks/circular_ref_6.ST: -------------------------------------------------------------------------------- 1 | TYPE 2 | d1 : fb_2; 3 | d2 : d3; 4 | d3 : d1; 5 | END_TYPE 6 | 7 | FUNCTION_BLOCK fb_1 8 | 9 | VAR 10 | var_fb_1 : d1; 11 | END_VAR 12 | 13 | ; 14 | 15 | END_FUNCTION_BLOCK 16 | 17 | FUNCTION_BLOCK fb_2 18 | 19 | VAR 20 | var_fb_2 : d2; 21 | END_VAR 22 | 23 | ; 24 | 25 | END_FUNCTION_BLOCK 26 | 27 | FUNCTION_BLOCK fb_3 28 | 29 | VAR 30 | var_fb_3 : d3; 31 | END_VAR 32 | 33 | ; 34 | 35 | END_FUNCTION_BLOCK 36 | 37 | PROGRAM t 38 | 39 | ; 40 | 41 | END_PROGRAM -------------------------------------------------------------------------------- /src/tests/programs/function_blocks/conditionals.ST: -------------------------------------------------------------------------------- 1 | FUNCTION_BLOCK fb_if 2 | 3 | VAR 4 | i1 : DINT; 5 | i2 : DINT; 6 | END_VAR 7 | 8 | if i1 = 1 then 9 | i2 := 10; 10 | elsif i1 = 2 then 11 | i2 := 20; 12 | elsif i1 = 3 then 13 | i2 := 30; 14 | else 15 | i2 := 40; 16 | end_if; 17 | 18 | END_FUNCTION_BLOCK 19 | 20 | 21 | PROGRAM t_if 22 | 23 | VAR 24 | fb : fb_if; 25 | END_VAR 26 | 27 | fb(); 28 | 29 | END_PROGRAM 30 | 31 | 32 | FUNCTION_BLOCK fb_case 33 | 34 | VAR 35 | i1 : DINT; 36 | i2 : DINT; 37 | END_VAR 38 | 39 | case i1 of 40 | 41 | 1: i2 := 10; 42 | 43 | 2: i2 := 20; 44 | 45 | 3: i2 := 30; 46 | 47 | else i2 := 40; 48 | 49 | end_case; 50 | 51 | END_FUNCTION_BLOCK 52 | 53 | 54 | PROGRAM t_case 55 | 56 | VAR 57 | fb : fb_case; 58 | END_VAR 59 | 60 | fb(); 61 | 62 | END_PROGRAM 63 | -------------------------------------------------------------------------------- /src/tests/programs/function_blocks/invoke.ST: -------------------------------------------------------------------------------- 1 | FUNCTION return_value : INT 2 | 3 | VAR_INPUT 4 | val1 : INT; 5 | val2 : INT; 6 | END_VAR 7 | 8 | return_value := val1 + val2; 9 | 10 | END_FUNCTION 11 | 12 | 13 | FUNCTION_BLOCK test_fb 14 | 15 | VAR_INPUT 16 | a : INT; 17 | b : INT; 18 | END_VAR 19 | 20 | VAR 21 | c : INT; 22 | END_VAR 23 | 24 | c := return_value(a, b); 25 | 26 | END_FUNCTION_BLOCK 27 | 28 | 29 | PROGRAM t 30 | 31 | VAR 32 | fb : test_fb; 33 | END_VAR 34 | 35 | fb(1, 2); 36 | 37 | END_PROGRAM -------------------------------------------------------------------------------- /src/tests/programs/function_blocks/loops.ST: -------------------------------------------------------------------------------- 1 | FUNCTION_BLOCK fb_for 2 | 3 | VAR 4 | itr : INT; 5 | out : ARRAY[1..5] of INT; 6 | out2 : ARRAY[1..5] of INT; 7 | END_VAR 8 | 9 | for itr := 1 to 5 do 10 | out[itr] := itr; 11 | out2[itr] := itr * 2; 12 | end_for; 13 | 14 | END_FUNCTION_BLOCK 15 | 16 | PROGRAM t_for 17 | 18 | VAR 19 | fb : fb_for; 20 | END_VAR 21 | 22 | fb(); 23 | 24 | END_PROGRAM 25 | 26 | 27 | FUNCTION_BLOCK fb_while 28 | 29 | VAR 30 | itr : INT := 0; 31 | control : INT := 0; 32 | control_two : INT := 0; 33 | itr_two : INT := 0; 34 | END_VAR 35 | 36 | while True do 37 | itr := itr + 1; 38 | 39 | if itr > 5 then 40 | exit; 41 | end_if; 42 | 43 | control := control + 1; 44 | 45 | end_while; 46 | 47 | while False do 48 | control_two := 100; 49 | end_while; 50 | 51 | while itr_two < 4 do 52 | itr_two := itr_two + 1; 53 | end_while; 54 | 55 | END_FUNCTION_BLOCK 56 | 57 | PROGRAM t_while 58 | 59 | VAR 60 | fb : fb_while; 61 | END_VAR 62 | 63 | fb(); 64 | 65 | END_PROGRAM 66 | 67 | 68 | FUNCTION_BLOCK fb_repeat 69 | 70 | VAR 71 | itr : INT := 0; 72 | control : INT := 0; 73 | control_two : INT := 0; 74 | itr_two : INT := 0; 75 | END_VAR 76 | 77 | repeat 78 | itr := itr + 1; 79 | 80 | if itr > 5 then 81 | exit; 82 | end_if; 83 | 84 | control := control + 1; 85 | until False 86 | end_repeat; 87 | 88 | repeat 89 | control_two := control_two + 1; 90 | until True 91 | end_repeat; 92 | 93 | repeat 94 | itr_two := itr_two + 1; 95 | until itr_two > 4 96 | end_repeat; 97 | 98 | END_FUNCTION_BLOCK 99 | 100 | PROGRAM t_repeat 101 | 102 | VAR 103 | fb : fb_repeat; 104 | END_VAR 105 | 106 | fb(); 107 | 108 | END_PROGRAM 109 | -------------------------------------------------------------------------------- /src/tests/programs/function_blocks/noninput.ST: -------------------------------------------------------------------------------- 1 | FUNCTION_BLOCK simple_s 2 | 3 | VAR_INPUT 4 | in : INT; 5 | END_VAR 6 | 7 | ; 8 | 9 | END_FUNCTION_BLOCK 10 | 11 | (* Assigning non-input variables *) 12 | PROGRAM bad_non_input 13 | 14 | VAR 15 | simple : simple_s; 16 | END_VAR 17 | 18 | simple(last:=1); 19 | 20 | END_PROGRAM 21 | -------------------------------------------------------------------------------- /src/tests/programs/function_blocks/qualified_assignment.ST: -------------------------------------------------------------------------------- 1 | FUNCTION_BLOCK test_fb 2 | 3 | VAR_INPUT 4 | ai : INT; 5 | bi : INT; 6 | END_VAR 7 | 8 | VAR 9 | a : ARRAY[1..5] of INT; 10 | b : ARRAY[1..5] of INT; 11 | END_VAR 12 | 13 | a[ai] := ai*100; 14 | b[bi] := bi*100; 15 | 16 | END_FUNCTION_BLOCK 17 | 18 | PROGRAM t 19 | 20 | VAR 21 | t1 : test_fb; 22 | t2 : test_fb; 23 | END_VAR 24 | 25 | t1(ai:=1, bi:=2); 26 | t2(ai:=5, bi:=3); 27 | 28 | END_PROGRAM 29 | 30 | 31 | FUNCTION_BLOCK test_fb_nest 32 | 33 | VAR 34 | t1 : test_fb; 35 | END_VAR 36 | 37 | t1(ai:=1, bi:=2); 38 | 39 | END_FUNCTION_BLOCK 40 | 41 | 42 | PROGRAM tnest 43 | 44 | VAR 45 | t : test_fb_nest; 46 | END_VAR 47 | 48 | t(); 49 | 50 | END_PROGRAM 51 | -------------------------------------------------------------------------------- /src/tests/programs/function_blocks/simple.ST: -------------------------------------------------------------------------------- 1 | FUNCTION_BLOCK simple_s 2 | 3 | VAR_INPUT 4 | in : INT; 5 | END_VAR 6 | 7 | 8 | VAR_OUTPUT 9 | out : INT; 10 | END_VAR 11 | 12 | VAR 13 | last : INT; 14 | END_VAR 15 | 16 | ; 17 | 18 | last := out; 19 | out := last + in; 20 | 21 | 22 | END_FUNCTION_BLOCK 23 | 24 | (* Calling variable amount of times *) 25 | PROGRAM t 26 | 27 | VAR 28 | a : INT; 29 | b : INT; 30 | itr : INT; 31 | simple : simple_s; 32 | END_VAR 33 | 34 | for itr := 1 to b do 35 | simple(in:=a); 36 | end_for; 37 | 38 | END_PROGRAM 39 | 40 | (* Calling without arguments *) 41 | PROGRAM no_args 42 | 43 | VAR 44 | simple : simple_s; 45 | END_VAR 46 | 47 | simple(); 48 | 49 | END_PROGRAM 50 | 51 | (* Wrong type for in *) 52 | PROGRAM bad_in_type 53 | 54 | VAR 55 | simple : simple_s; 56 | END_VAR 57 | 58 | simple(in:=true and false); 59 | 60 | END_PROGRAM 61 | -------------------------------------------------------------------------------- /src/tests/programs/function_blocks/simple_assignment.ST: -------------------------------------------------------------------------------- 1 | FUNCTION_BLOCK assign_s 2 | 3 | VAR_INPUT 4 | in : INT; 5 | END_VAR 6 | 7 | VAR 8 | out : INT; 9 | END_VAR 10 | 11 | out := in; 12 | 13 | END_FUNCTION_BLOCK 14 | 15 | PROGRAM t 16 | 17 | VAR 18 | a0 : assign_s; 19 | a1 : assign_s; 20 | a2 : assign_s; 21 | a3 : assign_s; 22 | END_VAR 23 | 24 | a1(10); 25 | a2(20); 26 | 27 | 28 | END_PROGRAM 29 | 30 | PROGRAM t2 31 | 32 | VAR 33 | a1 : assign_s; 34 | END_VAR 35 | 36 | ; 37 | 38 | END_PROGRAM 39 | -------------------------------------------------------------------------------- /src/tests/programs/function_blocks/toomany.ST: -------------------------------------------------------------------------------- 1 | FUNCTION_BLOCK simple_s 2 | 3 | VAR_INPUT 4 | in1 : INT; 5 | END_VAR 6 | 7 | ; 8 | 9 | END_FUNCTION_BLOCK 10 | 11 | (* Too many inputs *) 12 | PROGRAM bad_too_many 13 | 14 | VAR 15 | simple : simple_s; 16 | END_VAR 17 | 18 | simple(in1:=1, 10); 19 | 20 | END_PROGRAM 21 | -------------------------------------------------------------------------------- /src/tests/programs/function_blocks/undefined.ST: -------------------------------------------------------------------------------- 1 | FUNCTION_BLOCK simple 2 | 3 | ; 4 | 5 | END_FUNCTION_BLOCK 6 | 7 | (* Undefined fb handle *) 8 | PROGRAM bad_undefined 9 | 10 | simple(in:=1); 11 | 12 | END_PROGRAM 13 | -------------------------------------------------------------------------------- /src/tests/programs/literals.ST: -------------------------------------------------------------------------------- 1 | PROGRAM t 2 | 3 | VAR 4 | i1 : DINT; 5 | i2 : DINT; 6 | i3 : DINT; 7 | i4 : DINT; 8 | 9 | t1 : TIME; 10 | 11 | r1 : REAL; 12 | r2 : REAL; 13 | 14 | b1 : BOOL; 15 | b2 : BOOL; 16 | 17 | td : TIME_OF_DAY; 18 | d1 : DATE; 19 | dd : DATE_AND_TIME; 20 | 21 | str : STRING; 22 | wstr : WSTRING; 23 | END_VAR 24 | 25 | ; 26 | 27 | END_PROGRAM 28 | 29 | PROGRAM t_init 30 | 31 | VAR 32 | i1 : DINT := 1; 33 | i2 : DINT := 2; 34 | i3 : DINT := 3; 35 | i4 : DINT := 4; 36 | 37 | t1 : TIME := T#1s; 38 | 39 | r1 : REAL := 1.0; 40 | r2 : REAL := 2.0; 41 | 42 | b1 : BOOL := true; 43 | b2 : BOOL := false; 44 | 45 | td : TIME_OF_DAY := TOD#10:10:10.10; 46 | d1 : DATE := D#1234-01-02; 47 | dd : DATE_AND_TIME := DT#1234-01-01-10:10:10.10; 48 | 49 | str : STRING := 'single'; 50 | wstr : WSTRING := "double"; 51 | END_VAR 52 | 53 | ; 54 | 55 | END_PROGRAM 56 | -------------------------------------------------------------------------------- /src/tests/programs/loops/for.ST: -------------------------------------------------------------------------------- 1 | PROGRAM t 2 | 3 | VAR 4 | itr : INT; 5 | out : ARRAY[1..5] of INT; 6 | out2 : ARRAY[1..5] of INT; 7 | END_VAR 8 | 9 | for itr := 1 to 5 do 10 | out[itr] := itr; 11 | out2[itr] := itr * 2; 12 | end_for; 13 | 14 | 15 | END_PROGRAM 16 | -------------------------------------------------------------------------------- /src/tests/programs/loops/forexit.ST: -------------------------------------------------------------------------------- 1 | PROGRAM t 2 | 3 | VAR 4 | itr : INT; 5 | out : ARRAY[1..5] of INT; 6 | END_VAR 7 | 8 | for itr := 1 to 5 do 9 | out[itr] := itr; 10 | 11 | if itr = 2 then 12 | exit; 13 | end_if; 14 | 15 | end_for; 16 | 17 | END_PROGRAM 18 | -------------------------------------------------------------------------------- /src/tests/programs/loops/forrange.ST: -------------------------------------------------------------------------------- 1 | PROGRAM t 2 | 3 | VAR 4 | from_value : INT; 5 | to_value : INT; 6 | itr : INT; 7 | sum : INT; 8 | END_VAR 9 | 10 | for itr := from_value to to_value do 11 | sum := sum + itr; 12 | end_for; 13 | 14 | END_PROGRAM 15 | -------------------------------------------------------------------------------- /src/tests/programs/loops/repeat.ST: -------------------------------------------------------------------------------- 1 | PROGRAM t 2 | 3 | VAR 4 | itr : INT := 0; 5 | control : INT := 0; 6 | control_two : INT := 0; 7 | itr_two : INT := 0; 8 | END_VAR 9 | 10 | repeat 11 | itr := itr + 1; 12 | 13 | if itr > 5 then 14 | exit; 15 | end_if; 16 | 17 | control := control + 1; 18 | until False 19 | end_repeat; 20 | 21 | repeat 22 | control_two := control_two + 1; 23 | until True 24 | end_repeat; 25 | 26 | repeat 27 | itr_two := itr_two + 1; 28 | until itr_two > 4 29 | end_repeat; 30 | 31 | END_PROGRAM 32 | -------------------------------------------------------------------------------- /src/tests/programs/loops/repeatnotbool.ST: -------------------------------------------------------------------------------- 1 | PROGRAM t 2 | 3 | VAR 4 | itr : INT := 0; 5 | END_VAR 6 | 7 | repeat 8 | itr := itr + 1; 9 | until itr 10 | end_repeat; 11 | 12 | END_PROGRAM -------------------------------------------------------------------------------- /src/tests/programs/loops/while.ST: -------------------------------------------------------------------------------- 1 | PROGRAM t 2 | 3 | VAR 4 | itr : INT := 0; 5 | control : INT := 0; 6 | control_two : INT := 0; 7 | itr_two : INT := 0; 8 | END_VAR 9 | 10 | while True do 11 | itr := itr + 1; 12 | 13 | if itr > 5 then 14 | exit; 15 | end_if; 16 | 17 | control := control + 1; 18 | 19 | end_while; 20 | 21 | while False do 22 | control_two := 100; 23 | end_while; 24 | 25 | while itr_two < 4 do 26 | itr_two := itr_two + 1; 27 | end_while; 28 | 29 | END_PROGRAM 30 | -------------------------------------------------------------------------------- /src/tests/programs/loops/whilenotbool.ST: -------------------------------------------------------------------------------- 1 | PROGRAM t 2 | 3 | VAR 4 | itr : INT := 0; 5 | END_VAR 6 | 7 | while itr do 8 | itr := itr + 1; 9 | end_while; 10 | 11 | END_PROGRAM -------------------------------------------------------------------------------- /src/tests/programs/subrange/badrange.ST: -------------------------------------------------------------------------------- 1 | VAR_GLOBAL 2 | sr : INT(2..-10); 3 | END_VAR 4 | 5 | PROGRAM t 6 | 7 | ; 8 | 9 | END_PROGRAM 10 | -------------------------------------------------------------------------------- /src/tests/programs/subrange/basic.ST: -------------------------------------------------------------------------------- 1 | VAR_GLOBAL 2 | sr : INT(-10..2); 3 | sr_default : INT(-10..2) := 2; 4 | sr_one : INT(1..1); 5 | END_VAR 6 | 7 | PROGRAM t 8 | 9 | ; 10 | 11 | END_PROGRAM 12 | -------------------------------------------------------------------------------- /src/util/bitflag.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | #define ST_FLAG_IS_SET(collection, flags) (collection & (flags)) 26 | #define ST_SET_FLAGS(collection, flags) collection = collection | (flags) 27 | #define ST_CLEAR_FLAGS(collection, flags) collection = collection & ~(flags) 28 | 29 | -------------------------------------------------------------------------------- /src/util/config.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | 28 | static struct bool_option_t bool_options_template[] = { 29 | { .option = "resolve_links_on_parse_error", 30 | .value = ESSTEE_FALSE 31 | }, 32 | }; 33 | 34 | struct config_iface_t * st_new_config(void) 35 | { 36 | struct config_t *conf = NULL; 37 | struct bool_option_t *bool_options = NULL; 38 | 39 | ALLOC_OR_JUMP(conf, struct config_t, error_free_resources); 40 | bool_options = (struct bool_option_t *)malloc(sizeof(bool_options_template)); 41 | if(!bool_options) 42 | { 43 | goto error_free_resources; 44 | } 45 | 46 | memcpy( 47 | bool_options, 48 | bool_options_template, 49 | sizeof(bool_options_template)); 50 | 51 | conf->options_chunk = bool_options; 52 | conf->options_table = NULL; 53 | 54 | for(int i=0; i < sizeof(bool_options_template)/sizeof(struct bool_option_t); i++) 55 | { 56 | HASH_ADD_KEYPTR( 57 | hh, 58 | conf->options_table, 59 | conf->options_chunk[i].option, 60 | strlen(conf->options_chunk[i].option), 61 | &(conf->options_chunk[i])); 62 | } 63 | 64 | conf->config.get = st_config_get; 65 | conf->config.set = st_config_set; 66 | 67 | return &(conf->config); 68 | 69 | error_free_resources: 70 | free(conf); 71 | free(bool_options); 72 | return NULL; 73 | } 74 | 75 | int st_config_get( 76 | const struct config_iface_t *self, 77 | const char *option) 78 | { 79 | const struct config_t *conf = CONTAINER_OF(self, struct config_t, config); 80 | 81 | struct bool_option_t *found = NULL; 82 | 83 | HASH_FIND_STR(conf->options_table, option, found); 84 | if(!found) 85 | { 86 | return ESSTEE_ERROR; 87 | } 88 | 89 | return found->value; 90 | } 91 | 92 | int st_config_set( 93 | struct config_iface_t *self, 94 | const char *option, 95 | int value) 96 | { 97 | struct config_t *conf = CONTAINER_OF(self, struct config_t, config); 98 | 99 | struct bool_option_t *found = NULL; 100 | 101 | HASH_FIND_STR(conf->options_table, option, found); 102 | if(!found) 103 | { 104 | return ESSTEE_ERROR; 105 | } 106 | 107 | if(value == ESSTEE_TRUE) 108 | { 109 | found->value = ESSTEE_TRUE; 110 | } 111 | else 112 | { 113 | found->value = ESSTEE_FALSE; 114 | } 115 | 116 | return ESSTEE_OK; 117 | } 118 | 119 | void st_destroy_config( 120 | struct config_iface_t *self) 121 | { 122 | struct config_t *conf = CONTAINER_OF(self, struct config_t, config); 123 | 124 | free(conf->options_chunk); 125 | free(conf); 126 | } 127 | -------------------------------------------------------------------------------- /src/util/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | #include 25 | 26 | struct bool_option_t { 27 | const char *option; 28 | int value; 29 | 30 | UT_hash_handle hh; 31 | }; 32 | 33 | struct config_t { 34 | struct config_iface_t config; 35 | struct bool_option_t *options_table; 36 | struct bool_option_t *options_chunk; 37 | }; 38 | 39 | int st_config_get( 40 | const struct config_iface_t *self, 41 | const char *option); 42 | 43 | int st_config_set( 44 | struct config_iface_t *self, 45 | const char *option, 46 | int value); 47 | 48 | struct config_iface_t * st_new_config(void); 49 | 50 | void st_destroy_config( 51 | struct config_iface_t *self); 52 | -------------------------------------------------------------------------------- /src/util/iconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | struct config_iface_t { 23 | 24 | int (*get)( 25 | const struct config_iface_t *self, 26 | const char *option); 27 | 28 | int (*set)( 29 | struct config_iface_t *self, 30 | const char *option, 31 | int value); 32 | }; 33 | -------------------------------------------------------------------------------- /src/util/iissues.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | struct issue_group_iface_t { 27 | 28 | void (*close)( 29 | struct issue_group_iface_t *self); 30 | 31 | void (*main_issue)( 32 | struct issue_group_iface_t *self, 33 | const char *message, 34 | st_bitflag_t issue_class, 35 | int location_count, 36 | ...); 37 | 38 | }; 39 | 40 | struct issues_iface_t { 41 | 42 | void (*new_issue)( 43 | struct issues_iface_t *self, 44 | const char *format, 45 | st_bitflag_t issue_class, 46 | ...); 47 | 48 | void (*new_issue_at)( 49 | struct issues_iface_t *self, 50 | const char *message, 51 | st_bitflag_t issue_class, 52 | int location_count, 53 | ...); 54 | 55 | const char * (*build_message)( 56 | struct issues_iface_t *self, 57 | const char *format, 58 | ...); 59 | 60 | void (*memory_error)( 61 | struct issues_iface_t *self, 62 | const char *file, 63 | const char *function, 64 | int line); 65 | 66 | void (*internal_error)( 67 | struct issues_iface_t *self, 68 | const char *file, 69 | const char *function, 70 | int line); 71 | 72 | struct issue_group_iface_t * (*open_group)( 73 | struct issues_iface_t *self); 74 | 75 | void (*ignore_all)( 76 | struct issues_iface_t *self); 77 | 78 | const struct st_issue_t * (*fetch)( 79 | struct issues_iface_t *self, 80 | st_bitflag_t issue_filter); 81 | 82 | const struct st_issue_t * (*fetch_sub_issue)( 83 | struct issues_iface_t *self, 84 | const struct st_issue_t *issue, 85 | st_bitflag_t issue_filter); 86 | 87 | const struct st_issue_t * (*fetch_and_ignore)( 88 | struct issues_iface_t *self, 89 | st_bitflag_t issue_filter); 90 | 91 | struct issues_iface_t * (*merge)( 92 | struct issues_iface_t *self, 93 | struct issues_iface_t *to_merge); 94 | 95 | int (*unfetched_issues)( 96 | struct issues_iface_t *self, 97 | st_bitflag_t issue_filter); 98 | 99 | int (*count)( 100 | struct issues_iface_t *self, 101 | st_bitflag_t issue_filter); 102 | 103 | int (*fatal_error_occurred)( 104 | struct issues_iface_t *self); 105 | 106 | void (*destroy)( 107 | struct issues_iface_t *self, 108 | st_bitflag_t issue_filter); 109 | 110 | }; 111 | -------------------------------------------------------------------------------- /src/util/inamed_ref_pool.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | typedef int (*resolved_callback_t)( 28 | void *referrer, 29 | void *target, 30 | st_bitflag_t remark, 31 | const char *identifier, 32 | const struct st_location_t *location, 33 | const struct config_iface_t *config, 34 | struct issues_iface_t *issues); 35 | 36 | typedef int (*post_resolve_callback_t)( 37 | void *referrer, 38 | const struct config_iface_t *config, 39 | struct issues_iface_t *issues); 40 | 41 | struct named_ref_pool_iface_t { 42 | 43 | int (*add_two_step)( 44 | struct named_ref_pool_iface_t *self, 45 | const char *identifier, 46 | void *referrer, 47 | const struct st_location_t *location, 48 | resolved_callback_t callback, 49 | resolved_callback_t secondary_callback, 50 | struct issues_iface_t *issues); 51 | 52 | int (*add)( 53 | struct named_ref_pool_iface_t *self, 54 | const char *identifier, 55 | void *referrer, 56 | const struct st_location_t *location, 57 | resolved_callback_t callback, 58 | struct issues_iface_t *issues); 59 | 60 | int (*add_post_resolve)( 61 | struct named_ref_pool_iface_t *self, 62 | void *referrer, 63 | post_resolve_callback_t callback, 64 | struct issues_iface_t *issues); 65 | 66 | void (*commit)( 67 | struct named_ref_pool_iface_t *self); 68 | 69 | void (*clear)( 70 | struct named_ref_pool_iface_t *self); 71 | 72 | const char * (*next_unresolved)( 73 | struct named_ref_pool_iface_t *self); 74 | 75 | int (*resolve_with_remark)( 76 | struct named_ref_pool_iface_t *self, 77 | const char *identifier, 78 | void *target, 79 | st_bitflag_t remark); 80 | 81 | int (*resolve)( 82 | struct named_ref_pool_iface_t *self, 83 | const char *identifier, 84 | void *target); 85 | 86 | int (*reset_resolved)( 87 | struct named_ref_pool_iface_t *self); 88 | 89 | int (*trigger_resolve_callbacks)( 90 | struct named_ref_pool_iface_t *self, 91 | const struct config_iface_t *config, 92 | struct issues_iface_t *issues); 93 | 94 | struct named_ref_pool_iface_t * (*merge)( 95 | struct named_ref_pool_iface_t *self, 96 | struct named_ref_pool_iface_t *to_merge); 97 | 98 | void (*destroy)( 99 | struct named_ref_pool_iface_t *self); 100 | 101 | }; 102 | 103 | -------------------------------------------------------------------------------- /src/util/issue_context.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | struct issues_iface_t * st_new_issue_context(); 25 | -------------------------------------------------------------------------------- /src/util/macros.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #define ALLOC_ARRAY_OR_JUMP(var, type, size, jump) \ 27 | do { \ 28 | var = (type *)malloc(sizeof(type)*size); \ 29 | if(!var) \ 30 | { \ 31 | goto jump; \ 32 | } \ 33 | } while(0) 34 | 35 | #define ALLOC_ARRAY_OR_ERROR_JUMP(var, type, size, errors, jump) \ 36 | do { \ 37 | var = (type *)malloc(sizeof(type)*size); \ 38 | if(!var) \ 39 | { \ 40 | errors->memory_error(errors, __FILE__, __FUNCTION__, __LINE__); \ 41 | goto jump; \ 42 | } \ 43 | } while(0) 44 | 45 | #define STRDUP_OR_JUMP(var, str, jump) \ 46 | do { \ 47 | var = strdup(str); \ 48 | if(!var) \ 49 | { \ 50 | goto jump; \ 51 | } \ 52 | } while(0) 53 | 54 | #define STRDUP_OR_ERROR_JUMP(var, str, errors, jump) \ 55 | do { \ 56 | var = strdup(str); \ 57 | if(!var) \ 58 | { \ 59 | errors->memory_error(errors, __FILE__, __FUNCTION__, __LINE__); \ 60 | goto jump; \ 61 | } \ 62 | } while(0) 63 | 64 | #define ALLOC_OR_JUMP(var, type, jump) ALLOC_ARRAY_OR_JUMP(var, type, 1, jump) 65 | #define ALLOC_OR_ERROR_JUMP(var, type, errors, jump) ALLOC_ARRAY_OR_ERROR_JUMP(var, type, 1, errors, jump) 66 | 67 | /* The Linux container of macro */ 68 | #define CONTAINER_OF(ptr, type, member) \ 69 | ({ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 70 | (type *)( (char *)__mptr - offsetof(type,member) ); }) 71 | 72 | #define LOCDUP_OR_JUMP(var, loc, jump) \ 73 | do { \ 74 | var = (struct st_location_t *)malloc(sizeof(struct st_location_t)); \ 75 | if(!var) \ 76 | { \ 77 | goto jump; \ 78 | } \ 79 | else \ 80 | { \ 81 | memcpy(var, loc, sizeof(struct st_location_t)); \ 82 | } \ 83 | } while(0) 84 | 85 | #define LOCDUP_OR_ERROR_JUMP(var, loc, errors, jump) \ 86 | do { \ 87 | var = (struct st_location_t *)malloc(sizeof(struct st_location_t)); \ 88 | if(!var) \ 89 | { \ 90 | errors->memory_error(errors, __FILE__, __FUNCTION__, __LINE__); \ 91 | goto jump; \ 92 | } \ 93 | else \ 94 | { \ 95 | memcpy(var, loc, sizeof(struct st_location_t)); \ 96 | } \ 97 | } while(0) 98 | 99 | #define CHECK_WRITTEN_BYTES(X) \ 100 | do { \ 101 | if(X == 0) \ 102 | { \ 103 | return ESSTEE_FALSE; \ 104 | } \ 105 | else if(X < 0) \ 106 | { \ 107 | return ESSTEE_ERROR; \ 108 | } \ 109 | } while(0) 110 | 111 | #define TYPE_ANCESTOR(X) \ 112 | (X->ancestor) ? X->ancestor(X) : X 113 | -------------------------------------------------------------------------------- /src/util/named_ref_pool.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Kristian Nordman 3 | 4 | This file is part of esstee. 5 | 6 | esstee is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | esstee is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with esstee. If not, see . 18 | */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | struct named_ref_pool_iface_t * st_new_named_ref_pool( 26 | struct issues_iface_t *issues); 27 | -------------------------------------------------------------------------------- /utils/countlines.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | find ../src -name "*.[ylch]" -print | awk '!/bison.tab.c|flex.c|testground/' | xargs wc --lines | sort -n 4 | -------------------------------------------------------------------------------- /utils/todos.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | find ../src -name "*.[ch]" | xargs awk '/TODO:/ {todos+=1;sub(/[ \t]+/, "", $0);print todos" "$0" "FILENAME}' 4 | --------------------------------------------------------------------------------