From f9dd927ff40b8a77893ea81136958ee12de2e76b Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Wed, 28 Dec 2011 22:07:31 +0100 Subject: [PATCH] Move non-C++ simplification outside big loop. Related to commit b2f8161862287f1de900382f5bf9d42aa0734669 . --- lib/tokenize.cpp | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b0181db11..dd83dfbcd 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2025,23 +2025,6 @@ bool Tokenizer::tokenize(std::istream &code, tok->next()->str("-" + tok->next()->str()); } - // Simplify JAVA/C# code - if (isJava() && Token::Match(tok, ") throws %var% {")) - tok->deleteNext(2); - else if (isJavaOrCSharp() && tok->str() == "private") - tok->str("private:"); - else if (isJavaOrCSharp() && tok->str() == "protected") - tok->str("protected:"); - else if (isJavaOrCSharp() && tok->str() == "public") - tok->str("public:"); - - // Convert exclusive C# code - if (isCSharp() && Token::Match(tok, "%type% [ ] %var% [=;]") && - (!tok->previous() || Token::Match(tok->previous(), "[;{}]"))) { - tok->deleteNext(2); - tok->insertToken("*"); - } - // simplify round "(" parenthesis between "[;{}] and "{" if (Token::Match(tok, "[;{}] ( {") && Token::simpleMatch(tok->linkAt(2), "} ) ;")) { @@ -2050,6 +2033,35 @@ bool Tokenizer::tokenize(std::istream &code, } } + // Simplify JAVA/C# code + if (isJavaOrCSharp()) { + // better don't call isJava in the loop + bool isJava_ = isJava(); + for (Token *tok = _tokens; tok; tok = tok->next()) { + if (tok->str() == "private") + tok->str("private:"); + else if (tok->str() == "protected") + tok->str("protected:"); + else if (tok->str() == "public") + tok->str("public:"); + + else if (isJava_) { + if (Token::Match(tok, ") throws %var% {")) + tok->deleteNext(2); + } else { + if (Token::Match(tok, "%type% [ ] %var% [=;]") && + (!tok->previous() || Token::Match(tok->previous(), "[;{}]"))) { + tok->deleteNext(2); + tok->insertToken("*"); + tok = tok->tokAt(2); + if (tok->next()->str() == "=") + tok = tok->next(); + } + } + } + } + + // Convert K&R function declarations to modern C simplifyVarDecl(true); simplifyFunctionParameters();