Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed cycle checking. #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/jomlib/makefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ void Command::evaluateModifiers()
DescriptionBlock::DescriptionBlock(Makefile* mkfile)
: m_bFileExists(false),
m_bVisitedByCycleCheck(false),
m_bNoCyclesRootedHere(false),
m_canAddCommands(ACSUnknown),
m_pMakefile(mkfile)
{
Expand Down
1 change: 1 addition & 0 deletions src/jomlib/makefile.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class DescriptionBlock : public CommandContainer {
FileTime m_timeStamp;
bool m_bFileExists;
bool m_bVisitedByCycleCheck;
bool m_bNoCyclesRootedHere;
QVector<InferenceRule*> m_inferenceRules;

enum AddCommandsState { ACSUnknown, ACSEnabled, ACSDisabled };
Expand Down
50 changes: 49 additions & 1 deletion src/jomlib/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ void Parser::apply(Preprocessor* pp,
checkForCycles(target);
preselectInferenceRules(target);
}
// reset the droppings left by the cycle checker
foreach (const QString& targetName, m_activeTargets) {
DescriptionBlock *target = m_makefile->target(targetName);
resetCycleChecker(target);
}
}

MacroTable* Parser::macroTable()
Expand Down Expand Up @@ -637,20 +642,57 @@ void Parser::parseDotDirective()

void Parser::checkForCycles(DescriptionBlock* target)
{
#ifdef DEBUG_CYCLE_CHECKER
static int depth = 0;
#endif

if (!target)
return;

#ifdef DEBUG_CYCLE_CHECKER
{
int i = depth;
while (i--)
putc(' ', stdout);
}
printf("%s\n", qPrintable(target->targetName()));
#endif

if (target->m_bNoCyclesRootedHere)
return;

if (target->m_bVisitedByCycleCheck) {
QString msg = QLatin1String("cycle in targets detected: %1");
throw Exception(msg.arg(target->targetName()));
}

#ifdef DEBUG_CYCLE_CHECKER
depth++;
#endif
target->m_bVisitedByCycleCheck = true;
for (int i = target->m_dependents.count(); --i >= 0;) {
DescriptionBlock *const dep = m_makefile->target(target->m_dependents.at(i));
checkForCycles(dep);
}
target->m_bVisitedByCycleCheck = false;
#ifdef DEBUG_CYCLE_CHECKER
depth--;
#endif

target->m_bNoCyclesRootedHere = true;
}

void Parser::resetCycleChecker(DescriptionBlock* target)
{
if (!target || !target->m_bNoCyclesRootedHere)
return;

for (int i = target->m_dependents.count(); --i >= 0;) {
DescriptionBlock *const dep = m_makefile->target(target->m_dependents.at(i));
resetCycleChecker(dep);
}

target->m_bNoCyclesRootedHere = false;
}

QVector<InferenceRule*> Parser::findRulesByTargetName(const QString& targetFilePath)
Expand Down Expand Up @@ -684,7 +726,13 @@ QVector<InferenceRule*> Parser::findRulesByTargetName(const QString& targetFileP

void Parser::preselectInferenceRules(DescriptionBlock *target)
{
if (target->m_commands.isEmpty()) {
if (!target->m_commands.isEmpty()) {
/* If we already have commands for this target, then we've already
* generated all the commands for the dependents already. Nothing
* more to do. */
return;
}
{
QVector<InferenceRule *> rules = findRulesByTargetName(target->targetName());
if (!rules.isEmpty())
target->m_inferenceRules = rules;
Expand Down
1 change: 1 addition & 0 deletions src/jomlib/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Parser
void parseCommandLine(const QString& cmdLine, QList<Command>& commands, bool inferenceRule);
void parseInlineFiles(Command& cmd, bool inferenceRule);
void checkForCycles(DescriptionBlock* target);
void resetCycleChecker(DescriptionBlock* target);
QVector<InferenceRule*> findRulesByTargetName(const QString& targetFilePath);
void preselectInferenceRules(DescriptionBlock *target);
void error(const QString& msg);
Expand Down