mirror of https://github.com/vitalif/openscad
Detect circular includes. Probably the final commit for #75
parent
ebe59a0e4d
commit
b7cc740b78
11
src/lexer.l
11
src/lexer.l
|
@ -80,6 +80,7 @@ void includefile();
|
||||||
fs::path sourcepath();
|
fs::path sourcepath();
|
||||||
std::vector<fs::path> path_stack;
|
std::vector<fs::path> path_stack;
|
||||||
std::vector<FILE*> openfiles;
|
std::vector<FILE*> openfiles;
|
||||||
|
std::vector<std::string> openfilenames;
|
||||||
|
|
||||||
std::string filename;
|
std::string filename;
|
||||||
std::string filepath;
|
std::string filepath;
|
||||||
|
@ -142,6 +143,7 @@ use[ \t\r\n>]*"<" { BEGIN(cond_use); }
|
||||||
assert(!openfiles.empty());
|
assert(!openfiles.empty());
|
||||||
fclose(openfiles.back());
|
fclose(openfiles.back());
|
||||||
openfiles.pop_back();
|
openfiles.pop_back();
|
||||||
|
openfilenames.pop_back();
|
||||||
}
|
}
|
||||||
yypop_buffer_state();
|
yypop_buffer_state();
|
||||||
if (!YY_CURRENT_BUFFER)
|
if (!YY_CURRENT_BUFFER)
|
||||||
|
@ -227,10 +229,15 @@ void includefile()
|
||||||
PRINTB("WARNING: Can't find 'include' file '%s'.", filename);
|
PRINTB("WARNING: Can't find 'include' file '%s'.", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string fullname = boosty::absolute(finfo).string();
|
||||||
|
// Detect circular includes
|
||||||
|
BOOST_FOREACH(std::string &s, openfilenames) {
|
||||||
|
if (s == fullname) return;
|
||||||
|
}
|
||||||
|
|
||||||
filepath.clear();
|
filepath.clear();
|
||||||
path_stack.push_back(finfo.parent_path());
|
path_stack.push_back(finfo.parent_path());
|
||||||
|
|
||||||
std::string fullname = boosty::absolute(finfo).string();
|
|
||||||
handle_dep(fullname);
|
handle_dep(fullname);
|
||||||
currmodule->registerInclude(fullname);
|
currmodule->registerInclude(fullname);
|
||||||
yyin = fopen(fullname.c_str(), "r");
|
yyin = fopen(fullname.c_str(), "r");
|
||||||
|
@ -240,6 +247,7 @@ void includefile()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
openfiles.push_back(yyin);
|
openfiles.push_back(yyin);
|
||||||
|
openfilenames.push_back(fullname);
|
||||||
filename.clear();
|
filename.clear();
|
||||||
|
|
||||||
yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE));
|
yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE));
|
||||||
|
@ -253,5 +261,6 @@ void lexerdestroy()
|
||||||
{
|
{
|
||||||
BOOST_FOREACH (FILE *f, openfiles) fclose(f);
|
BOOST_FOREACH (FILE *f, openfiles) fclose(f);
|
||||||
openfiles.clear();
|
openfiles.clear();
|
||||||
|
openfilenames.clear();
|
||||||
path_stack.clear();
|
path_stack.clear();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue