MCPcopy Create free account
hub / github.com/Kitware/CMake / CheckNesting

Method CheckNesting

Source/cmListFileCache.cxx:330–421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

328}
329
330cm::optional<cmListFileContext> cmListFileParser::CheckNesting() const
331{
332 std::vector<NestingState> stack;
333
334 for (auto const& func : this->ListFile->Functions) {
335 auto const& name = func.LowerCaseName();
336 if (name == "if") {
337 stack.push_back({
338 NestingStateEnum::If,
339 cmListFileContext::FromListFileFunction(func, this->FileName),
340 });
341 } else if (name == "elseif") {
342 if (!TopIs(stack, NestingStateEnum::If)) {
343 return cmListFileContext::FromListFileFunction(func, this->FileName);
344 }
345 stack.back() = {
346 NestingStateEnum::If,
347 cmListFileContext::FromListFileFunction(func, this->FileName),
348 };
349 } else if (name == "else") {
350 if (!TopIs(stack, NestingStateEnum::If)) {
351 return cmListFileContext::FromListFileFunction(func, this->FileName);
352 }
353 stack.back() = {
354 NestingStateEnum::Else,
355 cmListFileContext::FromListFileFunction(func, this->FileName),
356 };
357 } else if (name == "endif") {
358 if (!TopIs(stack, NestingStateEnum::If) &&
359 !TopIs(stack, NestingStateEnum::Else)) {
360 return cmListFileContext::FromListFileFunction(func, this->FileName);
361 }
362 stack.pop_back();
363 } else if (name == "while") {
364 stack.push_back({
365 NestingStateEnum::While,
366 cmListFileContext::FromListFileFunction(func, this->FileName),
367 });
368 } else if (name == "endwhile") {
369 if (!TopIs(stack, NestingStateEnum::While)) {
370 return cmListFileContext::FromListFileFunction(func, this->FileName);
371 }
372 stack.pop_back();
373 } else if (name == "foreach") {
374 stack.push_back({
375 NestingStateEnum::Foreach,
376 cmListFileContext::FromListFileFunction(func, this->FileName),
377 });
378 } else if (name == "endforeach") {
379 if (!TopIs(stack, NestingStateEnum::Foreach)) {
380 return cmListFileContext::FromListFileFunction(func, this->FileName);
381 }
382 stack.pop_back();
383 } else if (name == "function") {
384 stack.push_back({
385 NestingStateEnum::Function,
386 cmListFileContext::FromListFileFunction(func, this->FileName),
387 });

Callers 1

ParseMethod · 0.95

Calls 5

TopIsFunction · 0.85
push_backMethod · 0.80
pop_backMethod · 0.80
backMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected