| 890 | |
| 891 | // Make sub routines. |
| 892 | template <typename T> static void makeSubRoutines(thread_db* tdbb, Statement* statement, |
| 893 | CompilerScratch* csb, T& subs) |
| 894 | { |
| 895 | typename T::Accessor subAccessor(&subs); |
| 896 | |
| 897 | for (auto& sub : subs) |
| 898 | { |
| 899 | auto subNode = sub.second; |
| 900 | auto subRoutine = subNode->routine; |
| 901 | auto& subCsb = subNode->subCsb; |
| 902 | |
| 903 | auto subStatement = Statement::makeStatement(tdbb, subCsb, false); |
| 904 | subStatement->parentStatement = statement; |
| 905 | subRoutine->setStatement(subStatement); |
| 906 | |
| 907 | // Dependencies should be added directly to the main routine while parsing. |
| 908 | fb_assert(subCsb->csb_dependencies.isEmpty()); |
| 909 | |
| 910 | // Move permissions from the sub routine to the parent. |
| 911 | |
| 912 | for (auto& access : subStatement->externalList) |
| 913 | { |
| 914 | FB_SIZE_T i; |
| 915 | if (!csb->csb_external.find(access, i)) |
| 916 | csb->csb_external.insert(i, access); |
| 917 | } |
| 918 | |
| 919 | for (auto& access : subStatement->accessList) |
| 920 | { |
| 921 | FB_SIZE_T i; |
| 922 | if (!csb->csb_access.find(access, i)) |
| 923 | csb->csb_access.insert(i, access); |
| 924 | } |
| 925 | |
| 926 | delete subCsb; |
| 927 | subCsb = NULL; |
| 928 | |
| 929 | statement->subStatements.add(subStatement); |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | |
| 934 | #ifdef DEV_BUILD |