MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / ast_requireModule

Function ast_requireModule

src/parser/parser_impl.cpp:1116–1152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1114 }
1115
1116 void ast_requireModule ( yyscan_t scanner, string * name, string * modalias, bool pub, const LineInfo & atName, string * guard ) {
1117 // Optional require `require ?guard target`: when the guard module is not available, skip the
1118 // require entirely (no error). A present guard with a missing target still errors below.
1119 if ( guard ) {
1120 bool guardAvailable = Module::requireEx(*guard, false) != nullptr;
1121 delete guard;
1122 if ( !guardAvailable ) {
1123 delete name;
1124 if ( modalias ) delete modalias;
1125 return;
1126 }
1127 }
1128 auto info = yyextra->g_Access->getModuleInfo(*name, yyextra->g_FileAccessStack.back()->name);
1129 if ( auto mod = yyextra->g_Program->addModule(info.moduleName) ) {
1130 yyextra->g_Program->allRequireDecl.push_back(make_tuple(mod,*name,info.fileName,pub,atName));
1131 yyextra->g_Program->thisModule->addDependency(mod, pub);
1132 das_collect_all_keywords(mod,scanner);
1133 if ( !info.importName.empty() ) {
1134 auto malias = modalias ? *modalias : info.importName;
1135 auto ita = yyextra->das_module_alias.find(malias);
1136 if ( ita !=yyextra->das_module_alias.end() ) {
1137 if ( ita->second != info.moduleName ) {
1138 das_yyerror(scanner,"module alias already used " + malias + " as " + ita->second,atName,
1139 CompilationError::already_declared_module);
1140 }
1141 } else {
1142 yyextra->das_module_alias[malias] = info.moduleName;
1143 }
1144 }
1145 } else {
1146 yyextra->g_Program->allRequireDecl.push_back(make_tuple((Module *)nullptr,*name,info.fileName,pub,atName));
1147 das_yyerror(scanner,"required module not found " + *name,atName,
1148 CompilationError::lookup_module);
1149 }
1150 delete name;
1151 if ( modalias) delete modalias;
1152 }
1153
1154 Expression * ast_forLoop ( yyscan_t, vector<VariableNameAndPosition> * iters, Expression * srcs,
1155 Expression * block, const LineInfo & locAt, const LineInfo & blockAt,

Callers 3

yyparseFunction · 0.85
yyparseFunction · 0.85
yyparseFunction · 0.85

Calls 9

das_collect_all_keywordsFunction · 0.85
addDependencyMethod · 0.80
das_yyerrorFunction · 0.70
getModuleInfoMethod · 0.45
addModuleMethod · 0.45
push_backMethod · 0.45
emptyMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected