Ejemplo n.º 1
0
//功能:除#define命令外逐条命令检测魔鬼数字
void ghostNum()
{
	int i;
	string temp = "";
	for(i=0; i<cmdCount; i++)
	{
		temp = command[i];
		if(!checkDef(temp))   // 如果不是#define语句,则需要判断是否含有魔鬼数字
		{
			checkNum(temp, i+1);  // 检查该条命令中的魔鬼数字
		}
	}
}
void ConstReturnTypeCheck::check(const MatchFinder::MatchResult &Result) {
  const auto *Def = Result.Nodes.getNodeAs<FunctionDecl>("func");
  CheckResult CR = checkDef(Def, Result);
  {
    // Clang only supports one in-flight diagnostic at a time. So, delimit the
    // scope of `Diagnostic` to allow further diagnostics after the scope.  We
    // use `getInnerLocStart` to get the start of the return type.
    DiagnosticBuilder Diagnostic =
        diag(Def->getInnerLocStart(),
             "return type %0 is 'const'-qualified at the top level, which may "
             "reduce code readability without improving const correctness")
        << Def->getReturnType();
    if (CR.ConstRange.isValid())
      Diagnostic << CR.ConstRange;
    for (auto &Hint : CR.Hints)
      Diagnostic << Hint;
  }
  for (auto Loc : CR.DeclLocs)
    diag(Loc, "could not transform this declaration", DiagnosticIDs::Note);
}
Ejemplo n.º 3
0
//功能:处理无用宏
void uselessMacro()
{
	int i=0;
	string temp = "";
	string single[255] = {""};
	string macroName = "";

	for(i=0; i<cmdCount; i++)
	{
		temp = command[i];
		
		if(checkDef(temp)) // 如果是宏定义语句
		{
			macroName = getMacroName(temp);  // 得到宏名
			if(1 == getMacroCount(macroName))  // 宏出现次数等于1则是没有用过
			{
				errNum[errLen] = i+1;
				errType[errLen] = 5;
				errLen++;
			}
		}
	}
}