void FasterStringFindCheck::registerMatchers(MatchFinder *Finder) {
  if (!getLangOpts().CPlusPlus)
    return;

  const auto SingleChar =
      expr(ignoringParenCasts(stringLiteral(hasSize(1)).bind("literal")));
  const auto StringFindFunctions =
      hasAnyName("find", "rfind", "find_first_of", "find_first_not_of",
                 "find_last_of", "find_last_not_of");

  Finder->addMatcher(
      cxxMemberCallExpr(
          callee(functionDecl(StringFindFunctions).bind("func")),
          anyOf(argumentCountIs(1), argumentCountIs(2)),
          hasArgument(0, SingleChar),
          on(expr(
              hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration(
                  recordDecl(hasAnyName(SmallVector<StringRef, 4>(
                      StringLikeClasses.begin(), StringLikeClasses.end()))))))),
              unless(hasSubstitutedType())))),
      this);
}
Example #2
0
 void LexerTests::runTests()
 {
   create();
   stringLiteral();
 }
Example #3
0
/**************************************************************
*	  Purpose:  Organizes the identification of tokens and types
*				by branching program into different directions,
*				utilyzing various other methods as needed,
*				depending on the first character of a subset,
*				places the token and type into a cToken object
*				and adds the cToken object to a vector.
*
*         Entry:  Method takes a vector of char of C text by reference.
*
*          Exit:  Returns a vector of cToken objects in the same
*					order that they appeared in the file vector
****************************************************************/
std::vector<cToken> cAnalyzer::analyze(std::vector<char> const &file)
{
	result.clear();
	it = file.begin();

	while (it != file.end())
	{
		if (*it == '\n')
		{
			result.push_back(cToken("RETURN", "Crg Rtrn"));
			it++;
		}
		else if (isspace(*it))
		{
			while (it != file.end() && isspace(*it) && *it != '\n')
			{
				it++;
			}
			result.push_back(cToken("SPACES", "spaces"));
		}
		else if (isdigit(*it) || *it == '.')
		{
			if (number(file) < 0)
				return result;
		}
		else if (isalpha(*it) || *it == '_')
		{
			if (identifier(file) < 0)
				return result;
		}
		else if (*it == '\"' || *it == '\'')
		{
			if (stringLiteral(file) < 0)
				return result;
		}
		else if (*it == '#')
		{
			std::string temp = std::string(it, it + 1);
			result.push_back(cToken(temp, "preprocessor"));
			it++;
		}
		else if (std::find(symbols.begin(), symbols.end(), *it) != symbols.end())
		{
			std::string temp = std::string(it, it + 1);
			result.push_back(cToken(temp, "symbol"));
			it++;
		}
		else if (std::find(operators.begin(), operators.end(), *it) != operators.end())
		{
			if (isOperator(file) < 0)
				return result;
		}
		else
		{
			std::string temp = std::string(it, it + 1);
			result.push_back(cToken(temp, error));
			it++;
		}
	}	

	return result;
}
Example #4
0
const String stringLiteralIfNotEmpty (const String& text)
{
    return text.isNotEmpty() ? stringLiteral (text) : String::empty;
}
#include "ExceptNumber.h"
#include "ASTUtility.h"
 

//TODO @TestNeed
static int count = 0;

//Declare a matcher of ASTNode to match magic number set
StatementMatcher FloatLiteralMatcher = floatLiteral().bind("floatliteral");

StatementMatcher IntLiteralMatcher = integerLiteral().bind("intliteral");

StatementMatcher StringLiteralMatcher = stringLiteral().bind("stringliteral");



//Declare a class Inherit clang::ast_matchers::MatchFinder::MatchCallback
class FloatChecker : public MatchFinder::MatchCallback {
public:
	virtual void run(const MatchFinder::MatchResult &Result)
    {
		//get the ASTContext
		clang::ASTContext *Context = Result.Context;
		//get the MagicNumberASTNode
		const clang::FloatingLiteral *fl = Result.Nodes.getNodeAs<clang::FloatingLiteral>("floatliteral");	
		//TODO handle the condition "without vaild data"
		if(!fl || ASTUtility::IsStmtInSTDFile(fl, Context)) return;
        ASTUtility::Print(fl, Context, "Rule049");
	}
};