69 return c >=
'A' && c <= 'Z' ? static_cast<char>(c -
'A' +
'a') : c;
75 result.reserve(text.size());
85 result.reserve(text.size());
87 if(c !=
' ' && c !=
'\t' && c !=
'\r' && c !=
'\n') {
96 return (c >=
'a' && c <=
'z') || (c >=
'A' && c <=
'Z') ||
97 (c >=
'0' && c <=
'9') || c ==
'_';
100inline std::string
trim(std::string_view text)
102 std::size_t first = 0;
103 while(first < text.size() &&
104 (text[first] ==
' ' || text[first] ==
'\t' ||
105 text[first] ==
'\r' || text[first] ==
'\n')) {
108 std::size_t last = text.size();
109 while(last > first &&
110 (text[last - 1] ==
' ' || text[last - 1] ==
'\t' ||
111 text[last - 1] ==
'\r' || text[last - 1] ==
'\n')) {
114 return std::string(text.substr(first, last - first));
117inline bool word_at(std::string_view source, std::size_t at,
118 std::string_view
word)
120 if(at +
word.size() > source.size() ||
122 (at +
word.size() < source.size() &&
126 for(std::size_t i = 0; i <
word.size(); ++i) {
135 std::size_t from = 0)
137 for(std::size_t i = from; i +
word.size() <= source.size(); ++i) {
142 return std::string_view::npos;
145inline std::size_t
skip_space(std::string_view text, std::size_t at)
147 while(at < text.size() &&
148 (text[at] ==
' ' || text[at] ==
'\t' || text[at] ==
'\r' ||
155inline std::string
read_ident(std::string_view text, std::size_t &at)
158 const std::size_t begin = at;
159 while(at < text.size() &&
ident_char(text[at])) {
162 return std::string(text.substr(begin, at - begin));
165inline std::vector<std::string>
split_top(std::string_view text,
char delimiter)
167 std::vector<std::string> result;
172 std::size_t begin = 0;
173 for(std::size_t i = 0; i < text.size(); ++i) {
174 const char c = text[i];
177 if(i + 1 < text.size() && text[i + 1] == quote) {
185 if(c ==
'\'' || c ==
'"') {
188 }
else if(c ==
'(') {
190 }
else if(c ==
')') {
192 }
else if(c ==
'[') {
194 }
else if(c ==
']') {
196 }
else if(c == delimiter && round == 0 && square == 0) {
197 result.push_back(
trim(text.substr(begin, i - begin)));
201 result.push_back(
trim(text.substr(begin)));
212 for(std::size_t i = 0; i + op.size() <= text.size(); ++i) {
213 const char c = text[i];
220 if(c ==
'\'' || c ==
'"') {
223 }
else if(c ==
'(') {
225 }
else if(c ==
')') {
227 }
else if(c ==
'[') {
229 }
else if(c ==
']') {
231 }
else if(round == 0 && square == 0 && text.substr(i, op.size()) == op) {
235 return std::string_view::npos;
239 std::vector<Var> &out)
241 for(
const std::string &entry :
split_top(block,
';')) {
246 if(
colon == std::string::npos) {
249 const std::string names =
trim(std::string_view(entry).substr(0,
colon));
250 std::string tail =
trim(std::string_view(entry).substr(
colon + 1));
252 std::string
type =
assign == std::string::npos
254 :
trim(std::string_view(tail).substr(0,
assign));
255 const std::string init =
assign == std::string::npos
257 :
trim(std::string_view(tail).substr(
assign + 2));
258 for(
const std::string &raw_name :
split_top(names,
',')) {
259 if(raw_name.empty()) {
263 const std::string lowered_name =
lower_copy(raw_name);
264 const std::size_t located = lowered_name.find(
" at ");
265 var.
name =
trim(std::string_view(raw_name).substr(0, located));
266 if(located != std::string::npos)
267 var.
location =
trim(std::string_view(raw_name).substr(located));
273 out.push_back(
static_cast<Var &&
>(var));
294 std::size_t word_end = at;
301 const std::size_t end =
find_word(content,
"end_var", word_end);
302 if(end == std::string::npos) {
303 pou.body = std::string(content.substr(at));
310 pou.body =
trim(content.substr(at));
314 std::vector<Diagnostic> &diagnostics)
317 while(at < source.size()) {
319 if(at >= source.size()) {
322 if(source.substr(at, 2) ==
"(*") {
323 const std::size_t close = source.find(
"*)", at + 2);
324 at = close == std::string::npos ? source.size() : close + 2;
327 if(
word_at(source, at,
"type")) {
328 const std::size_t end =
find_word(source,
"end_type", at + 4);
329 if(end == std::string::npos)
return false;
330 const std::size_t after = end + 8;
332 std::size_t name_at = at + 4;
335 unit.
source.assign(source.substr(at, after - at));
337 project.
types.append(source.substr(at, after - at));
338 project.
types.push_back(
'\n');
342 if(
word_at(source, at,
"var_global")) {
343 const std::size_t end =
find_word(source,
"end_var", at + 10);
344 if(end == std::string::npos)
return false;
351 std::string_view opener;
352 std::string_view closer;
353 if(
word_at(source, at,
"function_block")) {
355 opener =
"function_block";
356 closer =
"end_function_block";
357 }
else if(
word_at(source, at,
"function")) {
360 closer =
"end_function";
361 }
else if(
word_at(source, at,
"program")) {
364 closer =
"end_program";
369 std::size_t header = at + opener.size();
376 if(header < source.size() && source[header] ==
':') {
378 std::size_t line = source.find_first_of(
"\r\n", header);
379 for(
const std::string_view declaration :
380 {std::string_view{
"var"}, std::string_view{
"var_input"},
381 std::string_view{
"var_output"},
382 std::string_view{
"var_in_out"},
383 std::string_view{
"var_temp"}}) {
384 const std::size_t found =
find_word(source, declaration,
386 if(found != std::string_view::npos &&
387 (line == std::string_view::npos || found < line))
390 pou.return_type =
trim(source.substr(
391 header, (line == std::string_view::npos ? source.size() : line) - header));
392 header = line == std::string_view::npos ? source.size() : line;
395 const std::size_t end =
find_word(source, closer, header);
396 if(end == std::string::npos ||
pou.name.empty()) {
400 diagnostics.push_back(
static_cast<Diagnostic &&
>(diagnostic));
404 const std::size_t relative_body =
405 source.substr(header, end - header).find(
pou.body);
406 pou.body_source_offset = relative_body == std::string_view::npos
408 : header + relative_body;
409 for(std::size_t index = 0; index <
pou.body_source_offset; ++index)
410 if(source[index] ==
'\n') ++
pou.body_line;
411 project.
pous.push_back(
static_cast<Pou &&
>(
pou));
412 at = end + closer.size();
414 if(project.
pous.empty()) {
418 diagnostics.push_back(
static_cast<Diagnostic &&
>(diagnostic));
429 return left.lower < right.lower;
433 std::map<std::string, std::size_t> by_name;
435 for(std::size_t index = 0; index < project.
type_units.size(); ++index) {
436 if(!by_name.emplace(project.
type_units[index].lower, index).second)
440 std::vector<std::set<std::string>> dependencies(
442 bool parsed_all =
true;
443 for(std::size_t index = 0; index < project.
type_units.size(); ++index) {
444 const std::string probe = project.
type_units[index].source +
445 "\nPROGRAM L2BTypeOrder\nEND_PROGRAM\n";
460 if(!
field.type_name.empty())
466 std::vector<std::size_t> order;
468 std::vector<std::size_t> indegree(project.
type_units.size(), 0U);
469 std::vector<std::vector<std::size_t>> dependents(
471 for(std::size_t node = 0; node < dependencies.size(); ++node) {
472 for(
const std::string &dependency : dependencies[node]) {
473 const auto found = by_name.find(dependency);
474 if(found == by_name.end())
continue;
476 dependents[found->second].push_back(node);
479 std::set<std::pair<std::string, std::size_t>> ready;
480 for(std::size_t index = 0; index < indegree.size(); ++index) {
481 if(indegree[index] == 0U)
482 ready.emplace(project.
type_units[index].lower, index);
484 while(!ready.empty()) {
485 const std::size_t node = ready.begin()->second;
486 ready.erase(ready.begin());
487 order.push_back(node);
488 for(
const std::size_t dependent : dependents[node]) {
489 --indegree[dependent];
490 if(indegree[dependent] == 0U) {
491 ready.emplace(project.
type_units[dependent].lower,
498 if(order.size() != project.
type_units.size()) {
500 for(std::size_t index = 0; index < order.size(); ++index)
501 order[index] = index;
502 std::sort(order.begin(), order.end(),
503 [&project](std::size_t
left, std::size_t
right) {
504 if(project.type_units[left].lower !=
505 project.type_units[right].lower) {
506 return project.type_units[left].lower <
507 project.type_units[right].lower;
513 project.types.clear();
514 for(
const std::size_t index : order) {
515 project.types += project.type_units[index].source;
516 project.types.push_back(
'\n');
522 return find_word(source, word) != std::string_view::npos;
528 diagnostic.
code = code;
530 diagnostics.push_back(
static_cast<Diagnostic &&
>(diagnostic));
533inline const Var *
find_var(
const std::vector<Var> &vars, std::string_view name)
535 for(
const Var &var : vars) {
536 if(var.lower == name)
return &var;
545 if(
pou.lower == name &&
pou.kind == kind)
return &
pou;
553 std::vector<std::string> result;
554 for(
const Pou &candidate : project.
pous) {
557 while(at != std::string_view::npos) {
559 pou.body, at + candidate.
lower.size());
560 if(after <
pou.body.size() &&
pou.body[after] ==
'(') {
561 result.push_back(candidate.
lower);
568 std::sort(result.begin(), result.end());
569 result.erase(std::unique(result.begin(), result.end()), result.end());
574 std::set<std::string> &visiting,
bool &cycle)
576 if(!visiting.insert(
pou.lower).second) {
583 if(callee !=
nullptr) {
584 depth = std::max(depth,
585 1 +
call_depth(project, *callee, visiting, cycle));
588 visiting.erase(
pou.lower);
593 std::set<std::string> &visiting,
bool &cycle)
595 if(!visiting.insert(
pou.lower).second) {
600 for(
const Var &var :
pou.vars) {
603 if(child !=
nullptr) {
605 project, *child, visiting, cycle));
608 visiting.erase(
pou.lower);
623 std::vector<Actual> result;
624 for(
const std::string &part :
split_top(text,
',')) {
625 if(part.empty())
continue;
628 if(at != std::string::npos) {
629 actual.name =
lower_copy(
trim(std::string_view(part).substr(0, at)));
630 actual.value =
trim(std::string_view(part).substr(at + 2));
632 actual.output =
true;
635 if(at != std::string::npos) {
636 actual.name =
lower_copy(
trim(std::string_view(part).substr(0, at)));
637 actual.value =
trim(std::string_view(part).substr(at + 2));
643 result.push_back(
static_cast<Actual &&
>(actual));
651 if(at >= text.size() ||
652 !((text[at] >=
'A' && text[at] <=
'Z') ||
653 (text[at] >=
'a' && text[at] <=
'z') || text[at] ==
'_')) {
657 for(; at < text.size(); ++at) {
658 const char c = text[at];
659 if(c ==
'[') ++square;
660 else if(c ==
']') --square;
661 else if(square == 0 && !(
ident_char(c) || c ==
'.' || c ==
' ' ||
662 c ==
'\t'))
return false;
670 if(lower ==
"bool")
return "FALSE";
671 if(lower.rfind(
"string", 0) == 0)
return "''";
672 if(lower.rfind(
"wstring", 0) == 0)
return "\"\"";
679 static constexpr const char *names[] = {
680 "bool",
"sint",
"int",
"dint",
"lint",
"usint",
"uint",
681 "udint",
"ulint",
"byte",
"word",
"dword",
"lword",
"real",
682 "lreal",
"time",
"char",
"wchar",
"date",
"tod",
"dt",
683 "time_of_day",
"date_and_time"
685 for(
const char *name : names)
if(lower == name)
return true;
686 return lower.rfind(
"string", 0) == 0 || lower.rfind(
"wstring", 0) == 0;
700 std::vector<Diagnostic> &diagnostics_)
705 std::string
fresh(std::string_view stem)
707 std::string result =
"l2b" + std::to_string(
serial++);
714 void declare(
const std::string &name,
const std::string &type,
715 const std::string &init = {})
717 std::string line = name +
" : " +
type;
718 if(!init.empty()) line +=
" := " + init;
720 declarations.push_back(
static_cast<std::string &&
>(line));
724 std::string_view text,
const std::map<std::string, std::string> &symbols)
727 for(std::size_t i = 0; i < text.size();) {
728 if(text[i] ==
'\'' || text[i] ==
'"') {
729 const char quote = text[i];
731 out.push_back(text[i++]);
732 }
while(i < text.size() && text[i - 1] != quote);
735 if((text[i] >=
'A' && text[i] <=
'Z') ||
736 (text[i] >=
'a' && text[i] <=
'z') || text[i] ==
'_') {
737 const std::size_t begin = i++;
738 while(i < text.size() &&
ident_char(text[i])) ++i;
739 std::size_t compound_end = i;
740 if(i < text.size() && text[i] ==
'.') {
741 std::size_t j = i + 1;
742 if(j < text.size() &&
743 ((text[j] >=
'A' && text[j] <=
'Z') ||
744 (text[j] >=
'a' && text[j] <=
'z') || text[j] ==
'_')) {
746 while(j < text.size() &&
ident_char(text[j])) ++j;
750 const std::string key =
lower_copy(text.substr(
751 begin, compound_end - begin));
752 const auto found = symbols.find(key);
753 if(found != symbols.end()) {
754 out += found->second;
757 out.append(text.substr(begin, i - begin));
761 out.push_back(text[i++]);
771 for(std::size_t i = open; i < text.size(); ++i) {
772 const char c = text[i];
774 if(c == quote) quoted =
false;
777 if(c ==
'\'' || c ==
'"') { quoted =
true; quote = c; }
778 else if(c ==
'(') ++depth;
779 else if(c ==
')' && --depth == 0)
return i;
781 return std::string_view::npos;
787 const std::map<std::string, std::string> &symbols,
788 const std::map<std::string, std::string> &types)
792 for(std::size_t i = 0; i < text.size();) {
793 if(!((text[i] >=
'A' && text[i] <=
'Z') ||
794 (text[i] >=
'a' && text[i] <=
'z') || text[i] ==
'_')) {
798 const std::size_t begin = i++;
799 while(i < text.size() &&
ident_char(text[i])) ++i;
801 std::string_view(text).substr(begin, i - begin));
804 if(callee ==
nullptr || open >= text.size() || text[open] !=
'(') {
808 if(close == std::string::npos) {
811 return {prelude, text};
814 std::string_view(text).substr(open + 1, close - open - 1));
815 for(
Actual &actual : actuals) {
818 actual.prelude = nested.
prelude;
819 actual.value = nested.
value;
826 text.replace(begin, close - begin + 1, result);
827 i = begin + result.size();
829 return {prelude, text};
833 const std::vector<const Var *> &formals,
834 std::size_t formal_index,
835 std::string_view pseudo = {})
837 bool any_named =
false;
838 for(
const Actual &actual : actuals) any_named |= actual.named;
839 if(!pseudo.empty()) {
840 for(
const Actual &actual : actuals) {
841 if(actual.named && actual.name == pseudo)
return &actual;
846 for(
const Actual &actual : actuals) {
847 if(actual.named && actual.name == formals[formal_index]->lower)
852 std::size_t position = 0;
853 for(std::size_t i = 0; i < formals.size(); ++i) {
854 if(formals[i]->kind == VarKind::output)
continue;
855 if(i == formal_index) {
856 for(
const Actual &actual : actuals) {
857 if(actual.output)
continue;
858 if(position-- == 0)
return &actual;
868 std::vector<const Var *> &formals)
870 for(
const Var &var : callee.
vars) {
875 bool positional =
false;
876 std::set<std::string> names;
877 for(
const Actual &actual : actuals) {
880 if(!names.insert(actual.name).second) {
885 }
else positional =
true;
887 if(named && positional) {
892 std::vector<std::string> writable;
893 for(std::size_t i = 0; i < formals.size(); ++i) {
897 if(actual ==
nullptr)
continue;
899 if(std::find(writable.begin(), writable.end(), target) !=
905 writable.push_back(target);
907 for(std::size_t i = 0; i < formals.size(); ++i) {
919 const std::vector<Actual> &actuals,
922 struct Target { std::string
base; std::string index; };
923 std::vector<Target> targets;
924 for(std::size_t i = 0; i < formals.size(); ++i) {
928 if(actual ==
nullptr)
continue;
929 const std::string target =
trim(actual->value);
930 const std::size_t open = target.find(
'[');
931 const std::size_t close = target.rfind(
']');
932 if(open == std::string::npos || close <= open)
continue;
934 item.base =
lower_copy(
trim(std::string_view(target).substr(0, open)));
935 item.index =
trim(std::string_view(target).substr(
936 open + 1, close - open - 1));
937 for(
const Target &prior : targets) {
938 if(prior.base == item.base && prior.index != item.index) {
939 const std::string guard =
fresh(
"aliasguard");
941 code += guard +
" := L2B_ALIAS_GUARD((" + prior.index +
942 ") - (" + item.index +
"));";
945 targets.push_back(
static_cast<Target &&
>(item));
950 const std::string &type,
953 std::string result = source;
954 std::size_t search = 0;
955 while((search = result.find(
'[', search)) != std::string::npos) {
956 const std::size_t close = result.find(
']', search + 1);
957 if(close == std::string::npos)
break;
958 std::vector<std::string> indices =
split_top(
959 std::string_view(result).substr(search + 1,
960 close - search - 1),
',');
961 std::string replacement;
962 for(std::size_t i = 0; i < indices.size(); ++i) {
963 const std::string captured =
fresh(
"locator");
965 code += captured +
" := " + indices[i] +
";";
966 if(i != 0) replacement +=
",";
967 replacement += captured;
969 result.replace(search + 1, close - search - 1, replacement);
970 search += replacement.size() + 2;
972 if(result != source) {
973 const std::string checked =
fresh(
"boundcheck");
975 code += checked +
" := " + result +
";";
981 std::vector<Actual> &actuals, std::string &code)
983 std::size_t positional = 0;
984 for(
Actual &actual : actuals) {
985 code += actual.prelude;
986 const Var *formal =
nullptr;
987 if(actual.name ==
"en" || actual.name ==
"eno") {
991 const std::string captured =
fresh(
"actualen");
993 code += captured +
" := " + actual.value +
";";
994 actual.value = captured;
999 for(
const Var *candidate : formals) {
1000 if(candidate->lower == actual.name) formal = candidate;
1003 while(positional < formals.size() &&
1005 if(positional < formals.size()) formal = formals[positional++];
1007 if(formal ==
nullptr)
continue;
1012 const std::string captured =
fresh(
"actual");
1014 code += captured +
" := " + actual.value +
";";
1015 actual.value = captured;
1021 const Pou &callee, std::vector<Actual> actuals,
1022 const std::map<std::string, std::string> &caller_types,
1023 std::string &prelude)
1025 std::vector<const Var *> formals;
1029 const std::string prefix =
fresh(callee.
lower);
1030 const std::string ret = prefix +
"_ret";
1031 const std::string done = prefix +
"_done";
1034 std::map<std::string, std::string> symbols;
1035 std::map<std::string, std::string> types;
1036 symbols[callee.
lower] = ret;
1041 prelude += done +
" := FALSE;";
1042 for(std::size_t i = 0; i < formals.size(); ++i) {
1043 const Var &formal = *formals[i];
1046 if(actual ==
nullptr || !
lvalue(actual->value)) {
1051 const std::string actual_lower =
lower_copy(
trim(actual->value));
1052 const auto type = caller_types.find(actual_lower);
1057 symbols[formal.
lower] = actual->value;
1061 const std::string
local = prefix +
"_" + formal.
lower;
1066 prelude +=
local +
" := " + actual->value +
";";
1071 for(
const Var &var : callee.
vars) {
1078 const std::string
local = prefix +
"_" + var.
lower;
1082 prelude +=
local +
" := " +
1085 const Actual *en =
nullptr;
1086 const Actual *eno =
nullptr;
1087 for(
const Actual &actual : actuals) {
1088 if(actual.name ==
"en") en = &actual;
1089 if(actual.name ==
"eno") eno = &actual;
1091 if(eno !=
nullptr) prelude += eno->
value +
" := FALSE;";
1092 const std::string body =
transform_body(callee, symbols, types, {}, done);
1094 prelude +=
"IF " + en->
value +
" THEN " + body;
1095 if(eno !=
nullptr) prelude += eno->
value +
" := TRUE;";
1096 prelude +=
" END_IF;";
1099 if(eno !=
nullptr) prelude += eno->
value +
" := TRUE;";
1102 for(std::size_t i = 0; i < formals.size(); ++i) {
1103 const Var &formal = *formals[i];
1106 if(commit.empty()) commit =
"L2B_COMMIT(";
1108 commit += symbols[formal.
lower] +
"," + actual->value;
1111 if(!commit.empty()) prelude += commit +
");";
1119 std::string result =
"l2bi";
1120 for(
const std::string &segment :
split_top(path,
'.')) {
1121 result +=
"p" + std::to_string(segment.size());
1125 result +=
"m" + std::to_string(member.size());
1131 std::map<std::string, std::string> &symbols,
1132 std::map<std::string, std::string> &types,
1133 std::map<std::string, FbRef> &instances)
1135 for(
const Var &var :
type.vars) {
1138 if(child !=
nullptr) {
1139 const std::string child_path = path +
"." + var.
lower;
1140 instances[var.
lower] = {child, child_path};
1158 std::vector<Actual> actuals)
1160 std::vector<const Var *> formals;
1162 std::map<std::string, std::string> symbols;
1163 std::map<std::string, std::string> types;
1164 std::map<std::string, FbRef> nested;
1165 for(
const Var &var : ref.type->vars) {
1168 if(child !=
nullptr) {
1169 nested[var.
lower] = {child, ref.path +
"." + var.
lower};
1170 for(
const Var &pin : child->
vars) {
1182 symbols[var.
lower] = storage;
1189 const Actual *en =
nullptr;
1190 const Actual *eno =
nullptr;
1191 for(
const Actual &actual : actuals) {
1192 if(actual.name ==
"en") en = &actual;
1193 if(actual.name ==
"eno") eno = &actual;
1195 if(eno !=
nullptr) code += eno->
value +
" := FALSE;";
1196 for(std::size_t i = 0; i < formals.size(); ++i) {
1197 const Var &formal = *formals[i];
1200 code += symbols[formal.
lower] +
" := " + actual->value +
";";
1202 if(!
lvalue(actual->value)) {
1206 symbols[formal.
lower] = actual->value;
1210 for(
const Var &var : ref.type->vars) {
1215 const std::string done =
fresh(
"fb_done");
1217 code += done +
" := FALSE;";
1218 const std::string body =
transform_body(*ref.type, symbols, types,
1221 code +=
"IF " + en->
value +
" THEN " + body;
1222 if(eno !=
nullptr) code += eno->
value +
" := TRUE;";
1226 if(eno !=
nullptr) code += eno->
value +
" := TRUE;";
1229 for(std::size_t i = 0; i < formals.size(); ++i) {
1230 const Var &formal = *formals[i];
1233 if(commit.empty()) commit =
"L2B_COMMIT(";
1235 commit += symbols[formal.
lower] +
"," + actual->value;
1238 if(!commit.empty()) code += commit +
");";
1250 std::vector<StatementSlice> result;
1252 std::size_t begin = 0;
1253 for(std::size_t i = 0; i < body.size();) {
1254 if((body[i] >=
'A' && body[i] <=
'Z') ||
1255 (body[i] >=
'a' && body[i] <=
'z') || body[i] ==
'_') {
1256 const std::size_t word_begin = i++;
1257 while(i < body.size() &&
ident_char(body[i])) ++i;
1258 const std::string word =
lower_copy(body.substr(word_begin, i - word_begin));
1259 if(word ==
"if" || word ==
"case" || word ==
"for" ||
1260 word ==
"while" || word ==
"repeat") ++depth;
1261 else if(word ==
"end_if" || word ==
"end_case" ||
1262 word ==
"end_for" || word ==
"end_while" ||
1263 word ==
"end_repeat") --depth;
1266 if(body[i] ==
';' && depth == 0) {
1268 {std::string(body.substr(begin, i - begin + 1)), begin});
1272 const std::string tail =
trim(body.substr(begin));
1274 result.push_back({std::string(body.substr(begin)), begin});
1281 std::uint32_t column = 1;
1282 std::size_t bounded = std::min(offset, owner.
body.size());
1283 while(bounded < owner.
body.size() &&
1284 (owner.
body[bounded] ==
' ' || owner.
body[bounded] ==
'\t' ||
1285 owner.
body[bounded] ==
'\r' || owner.
body[bounded] ==
'\n'))
1287 for(std::size_t index = 0; index < bounded; ++index) {
1288 if(owner.
body[index] ==
'\n') {
1297 if(!path.empty()) path.push_back(
'/');
1300 return "(*@DBG " + owner.
lower +
" " + path +
" " +
1301 std::to_string(line) +
" " + std::to_string(column) +
" " +
1309 for(std::size_t i = from; i < text.size();) {
1310 if(!((text[i] >=
'A' && text[i] <=
'Z') ||
1311 (text[i] >=
'a' && text[i] <=
'z') || text[i] ==
'_')) {
1315 const std::size_t begin = i++;
1316 while(i < text.size() &&
ident_char(text[i])) ++i;
1317 const std::string token =
lower_copy(text.substr(begin, i - begin));
1318 if(token ==
"if") ++depth;
1319 else if(token ==
"end_if") {
1320 if(--depth == 0) { word = token;
return begin; }
1321 }
else if(depth == 1 && (token ==
"else" || token ==
"elsif")) {
1327 return std::string_view::npos;
1331 const Pou &owner,
const std::string &raw,
1332 const std::map<std::string, std::string> &symbols,
1333 const std::map<std::string, std::string> &types,
1334 const std::map<std::string, FbRef> &instances,
1335 const std::string &done, std::size_t origin)
1337 const std::size_t then_at =
find_word(raw,
"then", 2);
1338 if(then_at == std::string::npos)
return raw;
1340 trim(std::string_view(raw).substr(2, then_at - 2)), symbols, types);
1341 std::string separator;
1342 const std::size_t split =
if_separator(raw, then_at + 4, separator);
1343 if(split == std::string::npos)
return raw;
1344 std::string result = condition.
prelude +
"IF " + condition.
value +
1347 std::string_view(raw).substr(then_at + 4,
1348 split - then_at - 4),
1349 symbols, types, instances, done, origin + then_at + 4);
1350 if(separator ==
"else") {
1351 std::string end_word;
1352 const std::size_t end =
if_separator(raw, split + 4, end_word);
1354 owner, std::string_view(raw).substr(split + 4,
1356 symbols, types, instances, done, origin + split + 4);
1357 }
else if(separator ==
"elsif") {
1358 const std::string nested =
"IF " + raw.substr(split + 5);
1359 result +=
" ELSE " +
transform_if(owner, nested, symbols, types,
1361 origin + split + 5);
1363 result +=
" END_IF;";
1368 const Pou &owner,
const std::string &raw,
1369 const std::map<std::string, std::string> &symbols,
1370 const std::map<std::string, std::string> &types,
1371 const std::map<std::string, FbRef> &instances,
1372 const std::string &done, std::size_t origin)
1375 const std::size_t
assign = lower.find(
":=");
1377 const std::size_t by =
find_word(lower,
"by", to + 2);
1378 const std::size_t do_at =
find_word(lower,
"do", to + 2);
1379 const std::size_t end = lower.rfind(
"end_for");
1380 if(
assign == std::string::npos || to == std::string::npos ||
1381 do_at == std::string::npos || end == std::string::npos)
return raw;
1384 const std::size_t to_end = by != std::string::npos && by < do_at
1387 to + 2, to_end - to - 2)), symbols, types);
1389 if(by != std::string::npos && by < do_at) {
1391 by + 2, do_at - by - 2)), symbols, types);
1394 raw.substr(0,
assign + 2) +
" " + from.
value +
" TO " +
1396 if(by != std::string::npos && by < do_at) result +=
" BY " +
step.value;
1398 owner, std::string_view(raw).substr(do_at + 2, end - do_at - 2),
1399 symbols, types, instances, done, origin + do_at + 2);
1400 if(!done.empty()) result +=
"IF " + done +
" THEN EXIT; END_IF;";
1401 result +=
" END_FOR;";
1406 const Pou &owner,
const std::string &raw,
1407 const std::map<std::string, std::string> &symbols,
1408 const std::map<std::string, std::string> &types,
1409 const std::map<std::string, FbRef> &instances,
1410 const std::string &done, std::size_t origin)
1413 const std::size_t do_at =
find_word(lower,
"do", 5);
1414 const std::size_t end = lower.rfind(
"end_while");
1415 if(do_at == std::string::npos || end == std::string::npos)
return raw;
1417 5, do_at - 5)), symbols, types);
1418 std::string result =
"WHILE TRUE DO " + condition.
prelude +
1419 "IF NOT (" + condition.
value +
") THEN EXIT; END_IF;" +
1421 std::string_view(raw).substr(do_at + 2, end - do_at - 2),
1422 symbols, types, instances, done, origin + do_at + 2);
1423 if(!done.empty()) result +=
"IF " + done +
" THEN EXIT; END_IF;";
1424 result +=
" END_WHILE;";
1429 const Pou &owner, std::string_view source,
1430 const std::map<std::string, std::string> &symbols,
1431 const std::map<std::string, std::string> &types,
1432 const std::map<std::string, FbRef> &instances,
1433 const std::string &done, std::size_t origin = 0)
1437 std::string statement =
static_cast<std::string &&
>(slice.text);
1438 std::size_t leading = 0;
1439 for(
char value : statement) {
1440 if(value ==
' ' || value ==
'\t' || value ==
'\r' ||
1442 result.push_back(value);
1448 const std::size_t statement_origin =
1449 origin + slice.begin + leading;
1451 const std::string raw =
trim(statement);
1453 std::string emitted;
1454 if(lower ==
"return;") {
1455 emitted = done +
" := TRUE;";
1456 }
else if(
word_at(lower, 0,
"if")) {
1457 emitted =
transform_if(owner, raw, symbols, types, instances,
1458 done, statement_origin);
1459 }
else if(
word_at(lower, 0,
"for")) {
1460 emitted =
transform_for(owner, raw, symbols, types, instances,
1461 done, statement_origin);
1462 }
else if(
word_at(lower, 0,
"while")) {
1464 instances, done, statement_origin);
1469 const auto fb = instances.find(first);
1470 if(
fb != instances.end() &&
p < raw.size() && raw[
p] ==
'(') {
1473 std::string_view(raw).substr(
p + 1, close -
p - 1));
1474 for(
Actual &actual : actuals) {
1475 if(!actual.output) {
1477 actual.value, symbols, types);
1478 actual.prelude = expanded.
prelude;
1479 actual.value = expanded.
value;
1489 if(!done.empty() && lower !=
"return;" &&
1491 result +=
"IF NOT ";
1496 result +=
" END_IF;";
1505 const Pou &owner,
const std::map<std::string, std::string> &symbols,
1506 const std::map<std::string, std::string> &types,
1507 const std::map<std::string, FbRef> &instances,
1508 const std::string &done)
1512 types, instances, done, 0);
1534 TypeKind kind_, std::uint64_t string_capacity_)
1548 std::map<std::string, std::string> &types)
1553 types.emplace(key,
type);
1560 std::vector<Diagnostic> &diagnostics)
1562 std::map<std::string, std::string> types;
1568 for(
const Var &var :
pou.vars)
1572 std::string source = project.
types +
"PROGRAM L2BTypeProbe\n";
1573 if(!types.empty()) {
1575 std::size_t index = 0;
1576 for(
const auto &
type : types) {
1577 source +=
"l2bt" + std::to_string(index++) +
" : " +
1578 type.second +
";\n";
1580 source +=
"END_VAR\n";
1582 source +=
"END_PROGRAM\n";
1584 probe_options.
max_vars_bytes = std::numeric_limits<std::uint32_t>::max();
1587 diagnostics.insert(diagnostics.end(), probe.
diagnostics.begin(),
1592 std::size_t index = 0;
1593 for(
const auto &
type : types) {
1594 const std::string name =
"l2bt" + std::to_string(index++);
1597 if(candidate.
lower == name) {
1604 layouts[
type.first] = desc ==
nullptr
1615 if(candidate.
lower == name) {
1624 const std::size_t bytes =
fb_size(
fb->type);
1625 layouts[
type.first] = {
1626 static_cast<std::uint64_t
>((bytes +
kFbAlign - 1U) /
1628 static_cast<std::uint32_t
>(
kFbAlign)};
1635 const std::uint64_t alignment =
1636 std::min<std::uint32_t>(8U, std::max<std::uint32_t>(1U,
1638 const std::uint64_t mask = alignment - 1U;
1639 if(offset > std::numeric_limits<std::uint64_t>::max() - mask)
1641 offset = (offset + mask) & ~mask;
1642 if(layout.
size > std::numeric_limits<std::uint64_t>::max() - offset)
1644 offset += layout.
size;
1650 constexpr std::uint64_t mask = 7U;
1651 if(bytes > std::numeric_limits<std::uint64_t>::max() - mask)
1653 bytes = (bytes + mask) & ~mask;
1654 return bytes <= std::numeric_limits<std::uint32_t>::max();
1658 std::string_view type)
1661 return found == layouts.end() ? nullptr : &found->second;
1665 std::string_view left,
1666 std::string_view right)
1670 if(left_layout ==
nullptr || right_layout ==
nullptr ||
1679 if(left_string || right_string) {
1680 return left_layout->
kind == right_layout->
kind &&
1689 std::uint32_t &bytes,
1690 std::set<std::string> &visiting)
1692 if(!visiting.insert(
pou.lower).second)
return false;
1693 std::uint64_t total = 0;
1696 if(result ==
nullptr || !
append_layout(total, *result))
return false;
1698 for(
const Var &var :
pou.vars) {
1703 if(child !=
nullptr) {
1704 std::uint32_t child_bytes = 0;
1713 if(layout ==
nullptr || !
append_layout(total, *layout))
return false;
1715 visiting.erase(
pou.lower);
1717 bytes =
static_cast<std::uint32_t
>(total);
1723 std::uint32_t &bytes)
1725 std::set<std::string> visiting;
1731 std::uint32_t &bytes)
1733 std::uint64_t total = 0;
1734 for(
const Var &var :
pou.vars) {
1742 if(layout ==
nullptr || !
append_layout(total, *layout))
return false;
1745 bytes =
static_cast<std::uint32_t
>(total);
1751 std::string result = var.
name;
1753 result +=
" : " + var.
type;
1754 if(!var.
init.empty()) result +=
" := " + var.
init;
1761 std::vector<Diagnostic> &diagnostics,
1764 Expansion expansion{project, options, diagnostics};
1765 std::map<std::string, std::string> symbols;
1766 std::map<std::string, std::string> types;
1767 std::map<std::string, Expansion::FbRef> instances;
1768 std::set<std::string> declared;
1770 for(
const Var &var :
pou.vars) {
1774 if(declared.insert(
global.lower).second) {
1779 for(
const Var &var :
pou.vars) {
1787 const std::string path = expansion.
fresh(var.
lower);
1788 std::map<std::string, Expansion::FbRef> nested_instances;
1791 instances[var.
lower] = {
fb, path};
1792 for(
const Var &pin :
fb->vars) {
1808 const std::string result_name = expansion.
fresh(
"report_result");
1809 expansion.
declare(result_name,
pou.return_type);
1810 symbols[
pou.lower] = result_name;
1813 const std::string done = expansion.
fresh(
"report_done");
1814 expansion.
declare(done,
"BOOL");
1815 const std::string body = done +
" := FALSE;" + expansion.
transform_body(
1816 pou, symbols, types, instances, done);
1817 if(expansion.
failed)
return false;
1819 std::string transformed = project.
types +
"PROGRAM L2BReport\nVAR\n";
1820 for(
const std::string &declaration : expansion.
declarations) {
1821 transformed += declaration;
1822 transformed.push_back(
'\n');
1824 transformed +=
"END_VAR\n" + body +
"\nEND_PROGRAM\n";
1826 report_options.
max_vars_bytes = std::numeric_limits<std::uint32_t>::max();
1829 diagnostics.insert(diagnostics.end(), image.
diagnostics.begin(),
1841 std::vector<Diagnostic> &diagnostics,
1842 std::uint16_t &max_calls,
1843 std::uint16_t &max_instances)
1849 std::set<std::string> global_names;
1851 if(!global_names.insert(
global.lower).second) {
1856 std::set<std::string> names;
1858 if(!names.insert(
pou.lower).second) {
1862 std::size_t parameters = 0;
1863 for(
const Var &var :
pou.vars) {
1884 for(
const Pou &owner : project.
pous) {
1885 if(owner.
lower ==
pou.lower)
continue;
1886 for(
const Var &foreign : owner.
vars) {
1897 for(
const Var &var :
pou.vars) {
1911 for(
const Pou &candidate : project.
pous) {
1914 if(
call != std::string_view::npos) {
1917 bool declared =
false;
1918 for(
const Var &var :
pou.vars) {
1921 if(after <
pou.body.size() &&
pou.body[after] ==
'(' &&
1928 std::set<std::string> visiting;
1930 const int calls =
call_depth(project,
pou, visiting, cycle);
1935 max_calls = std::max(max_calls,
static_cast<std::uint16_t
>(calls));
1942 max_instances = std::max(max_instances,
1943 static_cast<std::uint16_t
>(instances));
1944 std::uint32_t frame_bytes = 0;
1963 const std::string lower =
lower_copy(source);
1964 const char *extensions[] = {
1965 "method",
"interface",
"extends",
"ref_to",
"generic"
1967 for(
const char *extension : extensions) {
1974 if(lower.find(
"function generic<") != std::string::npos) {
1984 std::uint16_t max_calls = 1;
1985 std::uint16_t max_instances = 1;
1987 max_calls, max_instances))
return result;
1989 std::vector<const Pou *> programs;
1993 std::sort(programs.begin(), programs.end(),
1995 return left->lower < right->lower;
1997 if(programs.empty()) {
2002 std::vector<Program> images;
2005 std::map<std::string, std::string> symbols;
2006 std::map<std::string, std::string> types;
2007 std::map<std::string, Expansion::FbRef> instances;
2026 *
program, symbols, types, instances, {});
2027 if(expansion.
failed)
return result;
2028 std::string transformed = project.
types +
"PROGRAM " +
program->name +
2030 for(
const std::string &declaration : expansion.
declarations) {
2031 transformed += declaration;
2032 transformed.push_back(
'\n');
2034 transformed +=
"END_VAR\n" + body +
"\nEND_PROGRAM\n";
2039 std::uint32_t transformed_body_line = 1;
2040 const std::size_t transformed_body = transformed.find(body);
2041 if(transformed_body != std::string::npos)
2042 for(std::size_t index = 0; index < transformed_body; ++index)
2043 if(transformed[index] ==
'\n') ++transformed_body_line;
2045 static_cast<std::int32_t
>(
program->body_line) -
2046 static_cast<std::int32_t
>(transformed_body_line);
2048 transformed, image_options,
true);
2057 const auto collect_calls = [&](
auto &&self,
const Pou &owner,
2058 std::uint16_t owner_depth) ->
void {
2059 for(
const Pou &callee : project.
pous) {
2062 while(
call != std::string::npos) {
2064 owner.body,
call + callee.
lower.size());
2065 if(open < owner.body.size() && owner.body[open] ==
'(') {
2068 site.
caller = owner.lower;
2071 for(std::size_t index = 0; index <
call; ++index)
2072 if(owner.body[index] ==
'\n') ++site.
call_line;
2076 const std::size_t next_line =
2077 owner.body.find(
'\n', open);
2079 if(next_line != std::string::npos) {
2081 for(std::size_t index = 0;
2082 index <= next_line; ++index)
2083 if(owner.body[index] ==
'\n')
2089 static_cast<std::uint16_t
>(owner_depth + 1U));
2095 collect_calls(collect_calls, *
program, 1);
2103 std::uint64_t image_fingerprint = 1469598103934665603ULL;
2104 for(
unsigned char byte : image_manifest) {
2105 image_fingerprint ^= byte;
2106 image_fingerprint *= 1099511628211ULL;
2112 var.
name = alias.first;
2113 var.
lower = alias.first;
2121 result.
program = images.front();
2122 result.
program.
programs =
static_cast<std::vector<Program> &&
>(images);
2129 std::uint32_t bytes = 0;
2135 const Program *report =
nullptr;
2144 if(report ==
nullptr) {
2149 report = &report_image;
2155 std::uint32_t offset = 0;
2166 if(root.
bytes > std::numeric_limits<std::uint32_t>::max() - offset) {
2170 offset += root.
bytes;
2171 std::vector<std::pair<const Pou *, std::string>> pending;
2178 for(std::size_t i = 0; i < pending.size(); ++i) {
2180 info.
name = pending[i].second;
2181 info.
lower = pending[i].second;
2189 if(info.
bytes > std::numeric_limits<std::uint32_t>::max() -
2194 offset += info.
bytes;
2195 for(
const Var &var : pending[i].first->vars) {
2198 if(child !=
nullptr)
2199 pending.push_back({child, pending[i].second +
"." + var.
lower});
2207 if(!
pou.worst_case_bounded) {
2214 pou.worst_case_instructions);
const TypeDesc * get(TypeId id) const noexcept
VarKind declaration_kind(std::string_view keyword)
bool instance_own_bytes(const Project &project, const Pou &pou, const TypeLayouts &layouts, std::uint32_t &bytes)
bool lvalue(std::string_view text)
bool word_at(std::string_view source, std::size_t at, std::string_view word)
std::vector< std::string > called_functions(const Project &project, const Pou &pou)
void parse_declarations(std::string_view block, VarKind kind, std::vector< Var > &out)
bool contains_word(std::string_view source, std::string_view word)
const TypeLayout * find_layout(const TypeLayouts &layouts, std::string_view type)
int call_depth(const Project &project, const Pou &pou, std::set< std::string > &visiting, bool &cycle)
bool finish_layout(std::uint64_t &bytes)
std::string default_value(std::string_view type)
std::string trim(std::string_view text)
void parse_unit_body(std::string_view content, Pou &pou)
std::size_t find_word(std::string_view source, std::string_view word, std::size_t from=0)
bool append_layout(std::uint64_t &offset, TypeLayout layout)
std::vector< Actual > parse_actuals(std::string_view text)
CompileResult compile_project(std::string_view source, const CompileOptions &options)
bool parse_project(std::string_view source, Project &project, std::vector< Diagnostic > &diagnostics)
std::string declaration_text(const Var &var)
std::size_t find_top_operator(std::string_view text, std::string_view op)
std::string lower_copy(std::string_view text)
std::size_t skip_space(std::string_view text, std::size_t at)
void normalize_project_order(Project &project, const CompileOptions &options)
int instance_type_depth(const Project &project, const Pou &pou, std::set< std::string > &visiting, bool &cycle)
std::vector< std::string > split_top(std::string_view text, char delimiter)
const Pou * find_pou(const Project &project, std::string_view name, PouKind kind)
bool compile_pou_report_image(const Project &project, const Pou &pou, const CompileOptions &options, std::vector< Diagnostic > &diagnostics, Program &report)
bool add_layout_type(const Project &project, const std::string &type, std::map< std::string, std::string > &types)
bool exact_declared_type(const TypeLayouts &layouts, std::string_view left, std::string_view right)
std::map< std::string, TypeLayout > TypeLayouts
bool build_type_layouts(const Project &project, const CompileOptions &options, TypeLayouts &layouts, std::vector< Diagnostic > &diagnostics)
std::string canonical_type_spelling(std::string_view text)
bool project_semantics(const Project &project, const CompileOptions &options, const TypeLayouts &layouts, std::vector< Diagnostic > &diagnostics, std::uint16_t &max_calls, std::uint16_t &max_instances)
bool pou_frame_bytes(const Project &project, const Pou &pou, const TypeLayouts &layouts, std::uint32_t &bytes, std::set< std::string > &visiting)
std::string read_ident(std::string_view text, std::size_t &at)
const Var * find_var(const std::vector< Var > &vars, std::string_view name)
void add_diag(std::vector< Diagnostic > &diagnostics, DiagCode code)
bool builtin_value_type(std::string_view type)
constexpr std::size_t kFbAlign
@ unsupported_l2b_object_extension
@ sema_standard_name_conflict
@ sema_unknown_identifier
@ sema_duplicate_argument
@ sema_fb_instance_required
@ sema_external_not_unique
@ sema_inout_requires_lvalue
constexpr const char * to_string(ConvKind kind)
CompileResult compile_single_program(std::string_view source, const CompileOptions &options=CompileOptions{})
CompileResult compile_single_program_impl(std::string_view source, const CompileOptions &options, bool trusted_debug_provenance)
bool is_reserved_standard_function(std::string_view lower)
constexpr std::size_t fb_size(FbType type) noexcept
constexpr TypeId invalid_type_id
std::vector< UserTypeDecl > user_types
std::int32_t debug_line_offset
bool debug_require_provenance
std::uint16_t debug_call_depth
std::uint32_t max_vars_bytes
std::uint16_t max_parameters_per_pou
std::uint16_t max_diagnostics
std::uint16_t max_instance_depth
std::uint16_t max_call_depth
std::vector< Diagnostic > diagnostics
std::uint32_t return_line
std::uint16_t callee_depth
std::uint32_t callee_line
std::uint32_t frame_bytes
std::uint64_t worst_case_instructions
std::vector< LocatedVarInfo > variables
std::uint64_t fingerprint
std::uint64_t worst_case_instructions
std::vector< DebugCallSite > debug_call_sites
std::uint16_t max_call_depth
std::uint32_t layout_bytes
std::string canonical_manifest() const
std::vector< FbInfo > fbs
std::uint16_t max_instance_depth
std::vector< Program > programs
std::vector< InstanceInfo > instances
std::vector< PouInfo > pous
std::vector< VarInfo > vars
ProcessImageInfo process_image
std::vector< StructFieldDecl > struct_fields
std::string element_type_name
std::string debug_directive(const Pou &owner, std::size_t offset) const
bool validate_actuals(const Pou &callee, const std::vector< Actual > &actuals, std::vector< const Var * > &formals)
static std::size_t matching_paren(std::string_view text, std::size_t open)
std::vector< StatementSlice > statements(std::string_view body)
std::string transform_body(const Pou &owner, const std::map< std::string, std::string > &symbols, const std::map< std::string, std::string > &types, const std::map< std::string, FbRef > &instances, const std::string &done)
std::string storage_name(std::string_view path, std::string_view member)
ExprExpansion expand_expr(std::string text, const std::map< std::string, std::string > &symbols, const std::map< std::string, std::string > &types)
std::vector< Diagnostic > & diagnostics
void capture_actuals(const std::vector< const Var * > &formals, std::vector< Actual > &actuals, std::string &code)
std::string expand_function(const Pou &callee, std::vector< Actual > actuals, const std::map< std::string, std::string > &caller_types, std::string &prelude)
std::string fresh(std::string_view stem)
std::string transform_sequence(const Pou &owner, std::string_view source, const std::map< std::string, std::string > &symbols, const std::map< std::string, std::string > &types, const std::map< std::string, FbRef > &instances, const std::string &done, std::size_t origin=0)
void declare_instance(const Pou &type, const std::string &path, std::map< std::string, std::string > &symbols, std::map< std::string, std::string > &types, std::map< std::string, FbRef > &instances)
const CompileOptions & options
std::string bind_dynamic_lvalue(const std::string &source, const std::string &type, std::string &code)
std::vector< std::string > declarations
std::string transform_if(const Pou &owner, const std::string &raw, const std::map< std::string, std::string > &symbols, const std::map< std::string, std::string > &types, const std::map< std::string, FbRef > &instances, const std::string &done, std::size_t origin)
const Actual * actual_for(const std::vector< Actual > &actuals, const std::vector< const Var * > &formals, std::size_t formal_index, std::string_view pseudo={})
std::size_t if_separator(std::string_view text, std::size_t from, std::string &word)
void declare(const std::string &name, const std::string &type, const std::string &init={})
static std::string replace_symbols(std::string_view text, const std::map< std::string, std::string > &symbols)
std::string expand_fb_call(const FbRef &ref, std::vector< Actual > actuals)
std::string transform_for(const Pou &owner, const std::string &raw, const std::map< std::string, std::string > &symbols, const std::map< std::string, std::string > &types, const std::map< std::string, FbRef > &instances, const std::string &done, std::size_t origin)
void emit_alias_guards(const std::vector< const Var * > &formals, const std::vector< Actual > &actuals, std::string &code)
Expansion(const Project &project_, const CompileOptions &options_, std::vector< Diagnostic > &diagnostics_)
std::vector< const Pou * > debug_stack_
std::map< std::string, std::string > public_aliases
std::string transform_while(const Pou &owner, const std::string &raw, const std::map< std::string, std::string > &symbols, const std::map< std::string, std::string > &types, const std::map< std::string, FbRef > &instances, const std::string &done, std::size_t origin)
std::size_t body_source_offset
std::vector< TypeUnit > type_units
std::vector< Var > globals
std::uint64_t string_capacity
TypeLayout(std::uint64_t size_, std::uint32_t alignment_)
TypeLayout(std::uint64_t size_, std::uint32_t alignment_, TypeId type_id_, TypeKind kind_, std::uint64_t string_capacity_)