当前位置: 首页>>代码示例>>C++>>正文


C++ StringVector::pop_back方法代码示例

本文整理汇总了C++中StringVector::pop_back方法的典型用法代码示例。如果您正苦于以下问题:C++ StringVector::pop_back方法的具体用法?C++ StringVector::pop_back怎么用?C++ StringVector::pop_back使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringVector的用法示例。


在下文中一共展示了StringVector::pop_back方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ParseFunctionName

/*!
 * Parses lines for function/procedure names.
 *
 * \param line line to be processed
 * \param lastline last line processed
 * \param functionStack stack of functions
 * \param functionName function name found
 *
 * \return 1 if function name is found
 * \return 0 if it is still in some function
 * \return 2 if the code line doesn't belong to any function
 */
int CVerilogCounter::ParseFunctionName(const string &line, string &lastline, StringVector &functionStack, string &functionName)
{
	string str;
	size_t idx;
	/* FIND KEYWORD "task" / "function" */
	static int func_flag = 0, task_flag = 0;
	/* FIND KEYWORD "task" / "function" */
	idx = CUtil::FindKeyword(line, "task");
	if (idx != string::npos)
	{
		if (idx + 5 < line.length())
		{
			str = line.substr(idx + 5);
			functionStack.push_back(str);
		}
		task_flag++;/* FOUND KEYWORD "task" */
	}
	
	idx = CUtil::FindKeyword(line, "function");
	if (idx != string::npos)
	{
		if (idx + 9 < line.length())
		{
			str = line.substr(idx + 9);
			functionStack.push_back(str);
		}
		func_flag++;/* FOUND KEYWORD "function" */
	}
    
	if (functionStack.empty())
	{
		// dealing with some code out of any subroutines, it a "main" code
		return 2;
	}
    
	idx = CUtil::FindKeyword(line, "endtask");
	if(idx != string::npos){
		task_flag--;
	}
	else{
		idx = CUtil::FindKeyword(line, "endfunction");
		if(idx != string::npos){
			func_flag--;
		}
	}
	
	if (idx != string::npos)
	{
		str = functionStack.back();
		functionStack.pop_back();
		idx = str.find(";");
		if (idx != string::npos)
		{
			functionName = CUtil::ClearRedundantSpaces(str.substr(0, idx));
			lastline=line; // warning fix
			return 1;
		}
	}
	return 0;
}
开发者ID:XiangyuLi926,项目名称:2016SummerUCCProject,代码行数:72,代码来源:CVerilogCounter.cpp

示例2: object

TEST_F(IdfFixture, IdfObject_GroupPushingAndPopping) {
  // NON-EXTENSIBLE OBJECT
  IdfObject object(IddObjectType::Lights);
  EXPECT_TRUE(object.pushExtensibleGroup().empty());

  // MINFIELDS INCLUDES AN EXTENSIBLE GROUP, BUT EXTENSIBLE GROUPS STILL INITIALIZED AS EMPTY
  object = IdfObject(IddObjectType::BuildingSurface_Detailed);
  EXPECT_EQ(static_cast<unsigned>(10),object.numFields());
  // push empty strings
  EXPECT_FALSE(object.pushExtensibleGroup().empty());
  EXPECT_EQ(static_cast<unsigned>(13),object.numFields());
  // push non-empty strings (correct number)
  StringVector values;
  values.push_back("2.1");
  values.push_back("100.0");
  values.push_back("0.0");
  EXPECT_FALSE(object.pushExtensibleGroup(values).empty());
  EXPECT_EQ(static_cast<unsigned>(16),object.numFields());
  // try to push incorrect number of non-empty strings
  values.pop_back();
  EXPECT_TRUE(object.pushExtensibleGroup(values).empty());
  EXPECT_EQ(static_cast<unsigned>(16),object.numFields());
  // pop until false
  StringVector result;
  result.push_back("Fake entry.");
  unsigned n = 16;
  while (!result.empty()) {
    result = object.popExtensibleGroup();
    if (!result.empty()) { n -= 3; }
    EXPECT_EQ(n,object.numFields());
  }
  EXPECT_EQ(static_cast<unsigned>(10),object.numFields());

}
开发者ID:ChengXinDL,项目名称:OpenStudio,代码行数:34,代码来源:IdfObject_GTest.cpp

示例3: canonicalize

void SystemPath::canonicalize()
{
    StringVector aNewPathComponents;

    for ( StringVector::const_iterator i( theComponents.begin() );
           i != theComponents.end(); ++i )
    {
        if ( *i == "." )
        {
            continue;
        }
        else if ( *i == ".." )
        {
            if ( aNewPathComponents.empty() )
            {
                break;
            }
            aNewPathComponents.pop_back();
        }
        else
        {
            aNewPathComponents.push_back( *i );
        }
    }

    theComponents.swap( aNewPathComponents );
}
开发者ID:ecell,项目名称:ecell3,代码行数:27,代码来源:FullID.cpp

示例4: LSLOC

/*!
* Extracts and stores logical lines of code.
* Determines and extract logical SLOC to place in the result variable
* using addSLOC function. Each time the addSLOC function is called,
* a new logical SLOC is added. This function assumes that the directive
* is handled before it is called.
*
* \param result counter results
* \param line processed physical line of code
* \param lineBak original physical line of code
* \param strLSLOC processed logical string
* \param strLSLOCBak original logical string
* \param paren_cnt count of parenthesis
* \param forflag found for flag
* \param found_forifwhile found for, if, or while flag
* \param found_while found while flag
* \param prev_char previous character
* \param data_continue continuation of a data declaration line
* \param temp_lines tracks physical line count
* \param phys_exec_lines number of physical executable lines
* \param phys_data_lines number of physical data lines
* \param inArrayDec marks an array declaration
* \param openBrackets number of open brackets (no matching close bracket)
* \param loopLevel nested loop level
*/
void CJavascriptCounter::LSLOC(results* result, string line, size_t lineNumber, string lineBak, string &strLSLOC, string &strLSLOCBak, unsigned int &paren_cnt,
							   bool &forflag, bool &found_forifwhile, bool &found_while, char &prev_char, bool &data_continue,
							   unsigned  int &temp_lines, unsigned int &phys_exec_lines, unsigned int &phys_data_lines, bool &inArrayDec,
							   unsigned int &openBrackets, StringVector &loopLevel)
{
	// paren_cnt is used with 'for' statement only
	size_t start = 0; //starting index of the working string
	size_t i = 0, strSize;
	bool found_do, found_try, found_else, trunc_flag = false;
	string exclude = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_$:";
	unsigned int cnt = 0;
	unsigned int loopCnt = 0;
	StringVector::iterator lit;

	string tmp = CUtil::TrimString(strLSLOC);

	// do, try
	found_do = (CUtil::FindKeyword(tmp, "do") != string::npos);
	found_try = (CUtil::FindKeyword(tmp, "try") != string::npos);
	// else is treated differently, else is included in SLOC, do and try are not
	found_else = (CUtil::FindKeyword(tmp, "else") != string::npos);

	// there may be more than 1 logical SLOC in this line
	while (i < line.length())
	{
		switch (line[i])
		{
		case ';': case '{': // LSLOC terminators
			                // ';' for normal executable or declaration statement
			                // '{' for starting a function or 'do' stmt or a block (which is counted)
			
			// get the previous logical mark until i-1 index is the new LSLOC
			// except 'do' precedes '{'
			// except '}' precedes ';' ??
			// do nothing inside 'for' statement
			if (paren_cnt > 0 && line[i] == ';')
				break;			
			
			// record open bracket for nested loop processing
			if (print_cmplx)
			{
				if (line[i] == '{')
				{
					openBrackets++;
					if ((unsigned int)loopLevel.size() < openBrackets)
						loopLevel.push_back("");
				}
				else
				{
					if ((unsigned int)loopLevel.size() > openBrackets && openBrackets > 0)
						loopLevel.pop_back();
				}
			}

			// case 'while(...);', 'while(...) {', and '} while(...);'
			// this case is handled in case ')'
			if (found_while && found_forifwhile) 
			{
				found_while = false;
				found_forifwhile = false;
				start = i + 1;
				break;
			}

			if (line[i] == '{')
			{
				if (prev_char == '=')
					inArrayDec = true;

				// continue until seeing ';'
				if (inArrayDec)
					break;

				// case for(...); and if (...) {
				// these specials are handled
//.........这里部分代码省略.........
开发者ID:carlyjiang,项目名称:UnifyCodeCounterObjectiveCCounter,代码行数:101,代码来源:CJavascriptCounter.cpp

示例5: ParseFunctionName


//.........这里部分代码省略.........
	{
		// check whether it is at first index, if yes then function name is at above line
		if (idx == 0)
		{
			functionStack.push_back(lastline);
			lastline.erase();
		}
		else
		{
			str = tline.substr(0, idx);
			tidx = cnt = cnt2 = 0;
			if (str[0] != '(' && str[0] != ':' && (lastline.length() < 1 || lastline[lastline.length() - 1] != ':'))
			{
				while (tidx != string::npos)
				{
					tidx = str.find('(', tidx);
					if (tidx != string::npos)
					{
						cnt++;
						tidx++;
					}
				}
				if (cnt > 0)
				{
					tidx = 0;
					while (tidx != string::npos)
					{
						tidx = str.find(')', tidx);
						if (tidx != string::npos)
						{
							cnt2++;
							tidx++;
						}
					}
				}
			}
			// make sure parentheses are closed and no parent class listed
			if ((cnt > 0 && cnt == cnt2) || (lastline.length() > 0 && lastline[lastline.length() - 1] == ';'))
				lastline = str;
			else
				lastline += " " + str;
			functionStack.push_back(CUtil::TrimString(lastline));
			lastline.erase();
		}
	}
	else if (tline.length() > 0 && tline[tline.length() - 1] != ';' &&
		lastline.length() > 0 && lastline[lastline.length() - 1] != ';')
	{
		// append until all parentheses are closed
		tidx = lastline.find('(');
		if (tidx != string::npos)
		{
			cnt = 1;
			while (tidx != string::npos)
			{
				tidx = lastline.find('(', tidx + 1);
				if (tidx != string::npos)
					cnt++;
			}
			tidx = lastline.find(')');
			while (tidx != string::npos)
			{
				cnt++;
				tidx = lastline.find(')', tidx + 1);
			}
			if (cnt % 2 != 0)
				lastline += " " + tline;
			else
				lastline = tline;
		}
		else
			lastline = tline;
	}
	else
		lastline = tline;

	idx = line.find('}');
	if (idx != string::npos && !functionStack.empty())
	{
		str = functionStack.back();
		functionStack.pop_back();
		idx = str.find('(');

		if (idx != string::npos)
		{
			// search for cyclomatic complexity keywords and other possible keywords
			CUtil::CountTally(str, cmplx_cyclomatic_list, cyclomatic_cnt, 1, exclude, "", "", 0, casesensitive);
			if (cyclomatic_cnt <= 0 && CUtil::FindKeyword(str, "switch") == string::npos &&
				CUtil::FindKeyword(str, "try") == string::npos && CUtil::FindKeyword(str, "finally") == string::npos &&
				CUtil::FindKeyword(str, "return") == string::npos && str.find('=') == string::npos)
			{
				functionName = CUtil::ClearRedundantSpaces(str.substr(0, idx));
				lastline.erase();
				return 1;
			}
		}
		lastline.erase();
	}
	return 0;
}
开发者ID:mpherg,项目名称:ucc,代码行数:101,代码来源:CCJavaCsCounter.cpp

示例6: LSLOC

/*!
* Extracts and stores logical lines of code.
* Determines and extract logical SLOC to place in the result variable
* using addSLOC function. Each time the addSLOC function is called,
* a new logical SLOC is added. This function assumes that the directive
* is handled before it is called.
*
* \param result counter results
* \param line processed physical line of code
* \param lineBak original physical line of code
* \param strLSLOC processed logical string
* \param strLSLOCBak original logical string
* \param cont_str continue string
* \param openBrackets number of open brackets (no matching close bracket)
* \param loopLevel nested loop level
*/
void CIdlCounter::LSLOC(results* result, string line, string lineBak, string &strLSLOC, string &strLSLOCBak,
    bool &cont_str, unsigned int &openBrackets, StringVector &loopLevel)
{
    size_t start = 0, len;
    size_t i = 0, j, k, strSize;
    bool trunc_flag = false;
    string tmp, tmpBak, str;

    int inlineStatement = 0;

    // check exclusions/continuation  
    tmp = CUtil::TrimString(line);
    tmpBak = CUtil::TrimString(lineBak);
    if (CUtil::FindKeyword(tmp, "end", 0, TO_END_OF_STRING, casesensitive) == 0 ||
        CUtil::FindKeyword(tmp, "endforeach", 0, TO_END_OF_STRING, casesensitive) == 0 ||
        CUtil::FindKeyword(tmp, "endfor", 0, TO_END_OF_STRING, casesensitive) == 0 ||
        CUtil::FindKeyword(tmp, "endwhile", 0, TO_END_OF_STRING, casesensitive) == 0 ||
        CUtil::FindKeyword(tmp, "endelse", 0, TO_END_OF_STRING, casesensitive) == 0 ||
        CUtil::FindKeyword(tmp, "endif", 0, TO_END_OF_STRING, casesensitive) == 0 ||
        CUtil::FindKeyword(tmp, "endcase", 0, TO_END_OF_STRING, casesensitive) == 0 ||
        CUtil::FindKeyword(tmp, "endswitch", 0, TO_END_OF_STRING, casesensitive) == 0)
    {
        if (loopLevel.size() > 0)
            loopLevel.pop_back();
        return;
    }
    else if (CUtil::FindKeyword(tmp, "repeat", 0, TO_END_OF_STRING, casesensitive) != string::npos &&
        CUtil::FindKeyword(tmp, "begin", 0, TO_END_OF_STRING, casesensitive) != string::npos)
    {
        if (loopLevel.size() > 0)
            loopLevel.pop_back();
        return;
    }
    else if (CUtil::FindKeyword(tmp, "else", 0, TO_END_OF_STRING, casesensitive) != string::npos &&
        tmp.find_first_of(":") != std::string::npos &&
        CUtil::FindKeyword(tmp, "begin", 0, TO_END_OF_STRING, casesensitive) != string::npos)
    {
        if (loopLevel.size() > 0)
            loopLevel.pop_back();
        return;
    }
    else if (CUtil::FindKeyword(tmp, "of", 0, TO_END_OF_STRING, casesensitive) == 0 )
    {
        strLSLOC += tmp + " ";
        strLSLOCBak += tmpBak + " ";
        return;
    }
    // process nested loops
    if (print_cmplx)
    {
        if (CUtil::FindKeyword(tmp, "for", 0, TO_END_OF_STRING, casesensitive) != string::npos ||
            CUtil::FindKeyword(tmp, "while", 0, TO_END_OF_STRING, casesensitive) != string::npos ||
            CUtil::FindKeyword(tmp, "foreach", 0, TO_END_OF_STRING, casesensitive) != string::npos ||
            CUtil::FindKeyword(tmp, "goto", 0, TO_END_OF_STRING, casesensitive) != string::npos ||
            CUtil::FindKeyword(tmp, "break", 0, TO_END_OF_STRING, casesensitive) != string::npos ||
            CUtil::FindKeyword(tmp, "continue", 0, TO_END_OF_STRING, casesensitive) != string::npos ||
            CUtil::FindKeyword(tmp, "until", 0, TO_END_OF_STRING, casesensitive) != string::npos)
        {
            loopLevel.push_back("loop");

            // record nested loop level
            unsigned int loopCnt = 0;
            for (StringVector::iterator lit = loopLevel.begin(); lit < loopLevel.end(); lit++)
            {
                if ((*lit) != "")
                    loopCnt++;
            }
            if ((unsigned int)result->cmplx_nestloop_count.size() < loopCnt)
                result->cmplx_nestloop_count.push_back(1);
            else
                result->cmplx_nestloop_count[loopCnt - 1]++;
        }
        else if (CUtil::FindKeyword(tmp, "if", 0, TO_END_OF_STRING, casesensitive) != string::npos ||
                 CUtil::FindKeyword(tmp, "case", 0, TO_END_OF_STRING, casesensitive) != string::npos ||
                 CUtil::FindKeyword(tmp, "switch", 0, TO_END_OF_STRING, casesensitive) != string::npos)
                loopLevel.push_back("");
    }

	if (CUtil::FindKeyword(tmp, "do", 0, TO_END_OF_STRING, casesensitive) != string::npos &&
                CUtil::FindKeyword(tmp, "begin", 0, TO_END_OF_STRING, casesensitive) == string::npos)
	{
                strSize = CUtil::TruncateLine(tmp.length(), strLSLOC.length(), this->lsloc_truncate, trunc_flag);
                if (strSize > 0)
                {
//.........这里部分代码省略.........
开发者ID:carlyjiang,项目名称:UnifyCodeCounterObjectiveCCounter,代码行数:101,代码来源:CIdlCounter.cpp

示例7: LSLOC


//.........这里部分代码省略.........
		if (print_cmplx)
		{
			str = CUtil::TrimString(tmp.substr(start, end - start + 1));
			if (CUtil::FindKeyword(str, "for") != string::npos
				|| CUtil::FindKeyword(str, "while") != string::npos
				|| CUtil::FindKeyword(str, "until")!= string::npos
				|| CUtil::FindKeyword(str, "select")!= string::npos)
			{
				if (CUtil::FindKeyword(str, "for") != string::npos)
					loopLevel.push_back("for");
				else if (CUtil::FindKeyword(str, "while")!= string::npos)
					loopLevel.push_back("while");
				else if (CUtil::FindKeyword(str, "until") != string::npos)
					loopLevel.push_back("until");
				else if (CUtil::FindKeyword(str, "select") != string::npos)
					loopLevel.push_back("");

				// record nested loop level
				if (CUtil::FindKeyword(str, "select") == string::npos)
				{
					unsigned int loopCnt = 0;
					for (StringVector::iterator lit = loopLevel.begin(); lit < loopLevel.end(); lit++)
					{
						if ((*lit) != "")
							loopCnt++;
					}
					if ((unsigned int)result->cmplx_nestloop_count.size() < loopCnt)
						result->cmplx_nestloop_count.push_back(1);
					else
						result->cmplx_nestloop_count[loopCnt-1]++;
				}
			}
			if (CUtil::FindKeyword(str, "done") != string::npos && loopLevel.size() > 0)
				loopLevel.pop_back();
		}

		// check for line containing excluded keywords
		for (StringVector::iterator it = exclude_keywords.begin(); it != exclude_keywords.end(); it++)
		{
			i = CUtil::FindKeyword(tmp, (*it), start, end);
			if (i != string::npos)
			{
				// strip specified keyword and skip if empty
				start = i + (*it).length();
				if (CUtil::CheckBlank(CUtil::TrimString(tmp.substr(start, end - start))))
					start = end + 1;
				break;
			}
		}
		if (start > end)
		{
			if (temp_lines == 0 && phys_data_lines == 0 && phys_exec_lines == 0)
				phys_exec_lines = 1;
			continue;
		}

		// check for continuation words
		found = false;
		if (tmp[end] == ';')
			str = CUtil::TrimString(tmp.substr(start, end - start));
		else
			str = CUtil::TrimString(tmp.substr(start, end - start + 1));
		for (StringVector::iterator it = continue_keywords.begin(); it != continue_keywords.end(); it++)
		{
			if (str == (*it))
			{
开发者ID:RMax2015,项目名称:Unified_Code_Count,代码行数:67,代码来源:CBashCounter.cpp

示例8: ProcessPath

bool CConverToMK::ProcessPath(const char* pszVCPath,
							  const char* pszPath,
							  string& strRes )
{
	if (0 == pszPath || !*pszPath)
	{
		return false;
	}

	if (strRes.size())
	{
		strRes = "";
	}

	filesystem::path kVCFile(pszVCPath);
	filesystem::path kMKFile(m_pszMKFile);
	filesystem::path kInputPath(pszPath);

	unsigned int uiParentFolderCount = 0;
	string strFilename = kInputPath.filename().string();

	kInputPath = kInputPath.parent_path();

	kVCFile = kVCFile.parent_path();
	kMKFile = kMKFile.parent_path();

	StringVector kVCSets;
	StringVector kMKSets;
	StringVector kTargetSets;
	StringVector kTempVC;

	BOOST_AUTO(pkInputPathPos,kInputPath.begin());
	BOOST_AUTO(pkVCPos,kVCFile.begin());
	BOOST_AUTO(pkMKPos,kMKFile.begin());

	while (pkInputPathPos != kInputPath.end())
	{
		string strPath = pkInputPathPos->string().c_str();

		if (strcmp(strPath.c_str(),"..") == 0)
		{
			uiParentFolderCount++;
			pkInputPathPos++;
			continue;
		}

		kTargetSets.push_back(strPath);
		pkInputPathPos++;
	}

	while (pkVCPos != kVCFile.end())
	{
		filesystem::path strVC = *pkVCPos;
		kVCSets.push_back(strVC.string());
		pkVCPos++;
	}

	kTempVC = kVCSets;

	while (0 < uiParentFolderCount)
	{
		kTempVC.pop_back();
		kVCSets.pop_back();
		uiParentFolderCount--;
	}

	while (pkMKPos != kMKFile.end())
	{
		string strVC = pkMKPos->string();
		kMKSets.push_back(strVC);
		pkMKPos++;
	}

	unsigned int uiMin = kMKSets.size() < kVCSets.size() ?
		kMKSets.size() : kVCSets.size();
	unsigned int uiIndex = 0;

	for (uiIndex = 0;uiIndex < uiMin;uiIndex++)
	{
		if (strcmp(kMKSets[uiIndex].c_str(),kVCSets[uiIndex].c_str()) != 0)
		{
			break;
		}
	}

	kMKSets.erase(kMKSets.begin(),kMKSets.begin() + uiIndex);
	kVCSets.erase(kVCSets.begin(),kVCSets.begin() + uiIndex);

	strRes += ".";
	string strPrePath = "";

	for (unsigned int uiIndex = 0;uiIndex < kTempVC.size();uiIndex++)
	{
		strPrePath += kTempVC[uiIndex];
		strPrePath += "\\";
	}

	for (unsigned int uiIndex = 0;uiIndex < kVCSets.size();uiIndex++)
	{
		strRes += "\\";
//.........这里部分代码省略.........
开发者ID:jonesgithub,项目名称:HHHH,代码行数:101,代码来源:ConverToMK.cpp

示例9: ParseFunctionName

/*!
 * Parses lines for function/method names.
 *
 * \param line line to be processed
 * \param needIndentation last line processed
 * \param functionStack stack of functions
 * \param functionName function name found
 *
 * \return 1 if function name is found
 */
int CPythonCounter::ParseFunctionName(const string &line, string & needIndentation, StringVector &functionStack, string &functionName, vector<int> &indenStack, int & numWS)
{
    	string str;
	size_t idx;
    	int functionWS = 0;
    	if(indenStack.empty()){
        	indenStack.push_back(0);
    	}
    	functionWS = indenStack.back(); // current function's indentation
    	if (functionStack.empty()) {        
        	functionStack.push_back("");
        	needIndentation = "";
    	}
    
    	string tmp;
    	//get white spaces
    	tmp = line;
    	tmp = CUtil::TrimString(tmp, -1);
    
    	numWS = (unsigned)(line.length() - tmp.length());

    	//last line is with "def", if needIndentation=="YES"
    	//not consider the body of function is in the same line of "def"
    	if(needIndentation.length() >= 3 && needIndentation == "YES"){
        	indenStack.push_back(numWS);
        	needIndentation = "";
    	}
    	string mark = needIndentation; 
    
	idx = CUtil::FindKeyword(line, "def");
	if (idx != string::npos)
	{
		if (idx + 4 < line.length())
		{
			str = line.substr(idx + 4);
			functionStack.push_back(str);
            		needIndentation = "YES"; //indicate next line need to get the indentation
		}
	}
    if (functionStack.size() == 1 || functionStack.size() == 0)
	{
		// dealing with some code out of any subroutines, it is a "main" code
		return 2;
	}
    
    	if(mark != "YES"){
        	if (functionWS > numWS && functionStack.size() > 1 ) {
		    	//the first element in functionStack is ""
		    
		    	//we need to get the function and pop the function from the functionStack
			if(needIndentation=="YES"){
				//we have already pushed the new function to the functionStack
				string tempp = functionStack.back(); //pop new function
				functionStack.pop_back();
				
				str = functionStack.back();
				functionStack.pop_back();
				
				functionStack.push_back(tempp); // push new function
				indenStack.pop_back(); //pop the function's indentation in the stack
			}
			else{
		        	str = functionStack.back();
		        	functionStack.pop_back();
		        	indenStack.pop_back(); //pop the function's indentation in the stack

			}
		   
			//get function's name
			idx = str.find("(");
			if (idx != string::npos)
			{
				functionName = CUtil::ClearRedundantSpaces(str.substr(0, idx));
				return 1;
			}
        	}
	}
	return 0;    
}
开发者ID:zackkk,项目名称:MIPS,代码行数:89,代码来源:CPythonCounter.cpp

示例10: processJsonFiles

void processJsonFiles(String path)
{
    try {
        std::cout << "[INFO] Processing " << path << " configuration file." << endl;

        boost::filesystem::path jsonPath(path);
        CSelectionData selectionData;
        CJsonReader reader = CJsonReader(path);

        String programName = reader.getStringFromProperty("program-name");
        if (programName.empty()) {
            std::cerr << "[ERROR] Program name is missing in configuration file:" << path << std::endl;
            return;
        }

        StringVector reductionList = reader.getStringVectorFromProperty("reduction-method");
        if (reductionList.empty()) {
            std::cerr << "[ERROR] reduction-algorithm is missing from the configuration file("
                      << path << ")." << std::endl;
            printPluginNames(kernel.getTestSuiteReductionPluginManager().getPluginNames());
            return;
        } else {
            int iteration = reader.getIntFromProperty("iteration");
            for (StringVector::const_iterator it = reductionList.begin(); it != reductionList.end(); ++it) {
                if (*it == "duplation" && !iteration) {
                    std::cerr << "[ERROR] Missing iteration parameter for duplation reduction method in configuration file: "
                              << path << "." << std::endl;
                    return;
                }

                if (*it == "random" && !iteration && reader.getIntVectorFromProperty("reduction-sizes").empty()) {
                    std::cerr << "[ERROR] Missing iteration or reduction-sizes parameter for random reduction method in configuration file: "
                              << path << "." << std::endl;
                    return;
                }

                try {
                    kernel.getTestSuiteReductionPluginManager().getPlugin(*it);
                } catch (std::out_of_range &e) {
                    std::cerr << "[ERROR] Invalid reduction algorithm name(" << *it
                              << ") in configuration file: " << path << "." << std::endl;
                    return;
                }
            }
        }

        String covPath = reader.getStringFromProperty("coverage-data");
        if (covPath[0] == '.') {
            covPath = jsonPath.parent_path().string() + "/" + covPath;
        }

        String resPath = reader.getStringFromProperty("results-data");
        if (resPath[0] == '.') {
            resPath = jsonPath.parent_path().string() + "/" + resPath;
        }

        if (exists(covPath)
                && exists(resPath)) {
            (std::cerr << "[INFO] loading coverage from " << covPath << " ...").flush();
            selectionData.loadCoverage(covPath);
            (std::cerr << " done\n[INFO] loading results from " << resPath << " ...").flush();
            selectionData.loadResults(resPath);
            (std::cerr << " done" << std::endl).flush();
        } else {
            std::cerr << "[ERROR] Missing or invalid input files in config file " << path << "." << std::endl;
            return;
        }

        if (reader.getBoolFromProperty("globalize")) {
            // Globalize data.
            (std::cerr << "[INFO] Globalizing ... ").flush();
            selectionData.globalize();
            selectionData.filterToCoverage();
            (std::cerr << " done" << std::endl).flush();
        }

        String dirPath = reader.getStringFromProperty("output-dir");
        if (dirPath[0] == '.') {
            dirPath = jsonPath.parent_path().string() + "/" + dirPath;
            reader.setProperty("output-dir", dirPath);
        }

        if (!(boost::filesystem::exists(dirPath))) {
            boost::filesystem::create_directory(dirPath);
        }

        boost::filesystem::path p = boost::filesystem::path(covPath).filename();

        while (!reductionList.empty()) {
            string reductionMethod = reductionList.back();
            reductionList.pop_back();
            ITestSuiteReductionPlugin *plugin = NULL;

            std::ofstream outStream((dirPath + "/" + reductionMethod + "-" + p.string() + ".reduced").c_str());
            if (!outStream.good()) {
                throw CException("Reduction output file error.", reader.getStringFromProperty("coverage-data") + ".reduced");
            }

            try {
                plugin = kernel.getTestSuiteReductionPluginManager().getPlugin(reductionMethod);
//.........这里部分代码省略.........
开发者ID:sed-szeged,项目名称:soda,代码行数:101,代码来源:main.cpp

示例11: CountComplexity

int CVerilogCounter::CountComplexity(filemap* fmap, results* result)
{
	if (classtype == UNKNOWN || classtype == DATAFILE)
		return 0;
	filemap::iterator fit;
	filemap fitBak;
	filemap::iterator fitForw, fitBack;//used to check prior an later lines for semicolons
	//unsigned int cnt;
	//string line, line2;
	string exclude = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_$><=:";
	tokLocVect conditionalVector;
	tokLocVect::reverse_iterator r_tlvIter;
	//StringVector::iterator strIter = this->cmplx_cond_list.begin(); warning fix
	string buf;			// have a buffer string
	stringstream ss;	// insert the string into a stream
	tokenLocation tl;
	int count;
	bool whenCont;
    
    	size_t idx;
	unsigned int cnt, ret, cyclomatic_cnt = 0, ignore_cyclomatic_cnt = 0, main_cyclomatic_cnt = 0, /*function_count = 0, */cyclomatic_logic_cnt = 0, main_cyclomatic_logic_cnt = 1, cyclomatic_case_cnt = 0, main_cyclomatic_case_cnt = 1; // warning fix
	string line, lastline, file_ext, function_name = "";
    	StringVector function_stack;
	stack<unsigned int> cyclomatic_stack;
	stack<unsigned int> cyclomatic_logic_stack;
	stack<unsigned int> cyclomatic_case_stack;
	bool process_cyclomatic_complexity = false;
    	bool first_line_in_main = true;

    	StringVector switch_case_key_list;
    	StringVector switch_case_stack;
    	switch_case_key_list.push_back(":");    
    
	// check whether to process cyclomatic complexity
	if (cmplx_cyclomatic_list.size() > 0)
	{
		process_cyclomatic_complexity = true;
		if (skip_cmplx_cyclomatic_file_extension_list.size() > 0)
		{
			idx = result->file_name.find_last_of(".");
			if (idx != string::npos)
			{
				file_ext = result->file_name.substr(idx);
				file_ext = CUtil::ToLower(file_ext);
				if (find(skip_cmplx_cyclomatic_file_extension_list.begin(), skip_cmplx_cyclomatic_file_extension_list.end(), file_ext) != skip_cmplx_cyclomatic_file_extension_list.end())
					process_cyclomatic_complexity = false;
			}
		}
	}
    
	for (fit = fmap->begin(); fit != fmap->end(); fit++)
	{
		line = fit->line;
        
		if (CUtil::CheckBlank(line))
			continue;
        
		line = " " + line;
        
		// mathematical functions
		cnt = 0;
		CUtil::CountTally(line, math_func_list, cnt, 1, exclude, "", "", &result->math_func_count, casesensitive);
		result->cmplx_math_lines += cnt;
        
		// trigonometric functions
		cnt = 0;
		CUtil::CountTally(line, trig_func_list, cnt, 1, exclude, "", "", &result->trig_func_count, casesensitive);
		result->cmplx_trig_lines += cnt;
        
		// logarithmic functions
		cnt = 0;
		CUtil::CountTally(line, log_func_list, cnt, 1, exclude, "", "", &result->log_func_count, casesensitive);
		result->cmplx_logarithm_lines += cnt;
        
		// calculations
		cnt = 0;
		CUtil::CountTally(line, cmplx_calc_list, cnt, 1, exclude, "", "", &result->cmplx_calc_count, casesensitive);
		result->cmplx_calc_lines += cnt;
        
		// conditionals
		cnt = 0;
		CUtil::CountTally(line, cmplx_cond_list, cnt, 1, exclude, "", "", &result->cmplx_cond_count, casesensitive);
		result->cmplx_cond_lines += cnt;
        
		// logical operators
		cnt = 0;
		StringVector tmpList = cmplx_logic_list;//making a temporary list with the '<=' operator removed from the list; counting it on another pass;
		tmpList.pop_back();
		CUtil::CountTally(line, tmpList, cnt, 1, exclude, "", "", &result->cmplx_logic_count, casesensitive);
		result->cmplx_logic_lines += cnt;
        
		// preprocessor directives
		cnt = 0;
		CUtil::CountTally(line, cmplx_preproc_list, cnt, 1, exclude, "", "", &result->cmplx_preproc_count, casesensitive);
		result->cmplx_preproc_lines += cnt;
        
		// assignments
		cnt = 0;
		tmpList.clear();
		tmpList = cmplx_assign_list;//making a temporary list with the '<=' operator removed from the list; counting it on another pass;
//.........这里部分代码省略.........
开发者ID:XiangyuLi926,项目名称:2016SummerUCCProject,代码行数:101,代码来源:CVerilogCounter.cpp

示例12: LSLOC

/*!
 * Extracts and stores logical lines of code.
 * Determines and extract logical SLOC to place in the result variable
 * using addSLOC function. Each time the addSLOC function is called,
 * a new logical SLOC is added. This function assumes that the directive
 * is handled before it is called.
 *
 * \param result counter results
 * \param line processed physical line of code
 * \param lineBak original physical line of code
 * \param strLSLOC processed logical string
 * \param strLSLOCBak original logical string
 * \param paren_cnt count of parenthesis
 * \param forflag found for flag
 * \param found_forifwhile found for, if, or while flag
 * \param found_while found while flag
 * \param prev_char previous character
 * \param data_continue continuation of a data declaration line
 * \param temp_lines tracks physical line count
 * \param phys_exec_lines number of physical executable lines
 * \param phys_data_lines number of physical data lines
 * \param found_for found for loop
 * \param loopLevel nested loop level
 * \param always_flag found always
 * \param case_flag found case
 * \param repeat_flag found repeat
 */
void CVerilogCounter::LSLOC(results* result, string line, size_t lineNumber, string lineBak, string &strLSLOC, string &strLSLOCBak, 
				unsigned int &paren_cnt, bool &forflag, bool &found_forifwhile, bool &found_while, char &prev_char, 
				bool &data_continue, unsigned int &temp_lines, unsigned int &phys_exec_lines, unsigned int &phys_data_lines,
				bool &found_for, StringVector &loopLevel, bool &always_flag, bool &case_flag, bool &repeat_flag)
{
	// paren_cnt is used with 'for' statement only
	size_t start = 0, startmax = 0; // starting index of the working string
	size_t i = 0, strSize;
	bool trunc_flag = false;
	string exclude = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_$:";
	string dataExclude = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_$:().";	// avoid double count of casts as data and executable lines (e.g. set { m_uiValue = (uint)value; }
	bool found_end = false, found_endcase = false;
	unsigned int cnt = 0;
	bool newline = true;
    
	string tmp = CUtil::TrimString(strLSLOC);
	size_t tmpi;
    
	// there may be more than 1 logical SLOC in this line
	while (i < line.length())
	{
		tmp = CUtil::TrimString(line.substr(start, i + 1 - start));
		if (CUtil::FindKeyword(tmp, "end") != string::npos && loopLevel.size() > 0 && loopLevel.back().compare("begin") == 0)
		{
			loopLevel.pop_back();	// pop begin
			loopLevel.pop_back();	// pop looping
			start = i + 1;
		}
		if ((tmpi = CUtil::FindKeyword(line.substr(start, i + 1 - start), "generate")) != string::npos)
		{
			strSize = CUtil::TruncateLine(i + 1 - start, strLSLOC.length(), this->lsloc_truncate, trunc_flag);
			if (strSize > 0)
			{
				strLSLOC += line.substr(start, strSize);
				strLSLOCBak += lineBak.substr(start, strSize);
			}
			if (result->addSLOC(strLSLOCBak, lineNumber, trunc_flag))
				result->exec_lines[LOG]++;
			strLSLOCBak = strLSLOC = "";
			phys_exec_lines = temp_lines;
			temp_lines = 0;
			start = start + 7 + tmpi;
			found_forifwhile = false;
			forflag = false;
			found_for = false;
			always_flag = false;
			case_flag = false;
			repeat_flag = false;
		}
        
		if ((tmpi = CUtil::FindKeyword(line.substr(start, i + 1 - start), "forever")) != string::npos)
		{
			if (print_cmplx)
			{
				tmp = CUtil::TrimString(line.substr(start, i + 1 - start));
				tmp = strLSLOC + " " + tmp;
				if (CUtil::FindKeyword(tmp, "begin") != string::npos && loopLevel.size() > 0 && loopLevel.back().compare("looping") == 0)
				{
					loopLevel.push_back("begin");
				}
				else if (loopLevel.size() > 0)
				{
					// didn't find begin, so pop off since no longer in a looping block
					loopLevel.pop_back();
				}
				loopLevel.push_back("looping");
				// forever doesn't have any conditions so just add it to sloc
				unsigned int loopCnt = 0;
				for (StringVector::iterator lit = loopLevel.begin(); lit < loopLevel.end(); lit++)
				{
					if ((*lit) != "begin")
						loopCnt++;
				}
//.........这里部分代码省略.........
开发者ID:XiangyuLi926,项目名称:2016SummerUCCProject,代码行数:101,代码来源:CVerilogCounter.cpp

示例13: LSLOC


//.........这里部分代码省略.........
							}
							k--;
							str = CUtil::TrimString(tmp.substr(j, k - j + 1));
							if (CUtil::IsInteger(str))
							{
								loopEnd.push_back(str);
								found = true;
							}
							break;
						}
					}
				}
				if (!found)
					loopEnd.push_back("end do");
				new_loop = true;
			}
			else
			{
				i = CUtil::FindKeyword(tmp, "end forall", start, end, false);
				if (i != string::npos)
					i = string::npos;
				else
					i = CUtil::FindKeyword(tmp, "forall", start, end, false);
				if (i != string::npos)
				{
					loopEnd.push_back("end forall");
					new_loop = true;
				}
				else if (loopEnd.size() > 0)
				{
					str = loopEnd.back();
					if (CUtil::FindKeyword(tmp, str, start, end, false) != string::npos)
					{
						loopEnd.pop_back();
						if (CUtil::IsInteger(str))
						{
							// remove additional label terminators
							if (loopEnd.size() > 0)
							{
								for (m = loopEnd.size() - 1; m > 0; m--)
								{
									if (loopEnd[m] == str)
										loopEnd.pop_back();
									else
										break;
								}
								if (m == 0)
								{
									if (loopEnd[0] == str)
										loopEnd.pop_back();
								}
							}
						}
					}
					else if (loopEnd.back() == "end do")
					{
						if (CUtil::FindKeyword(tmp, "enddo", start, end, false) != string::npos)
							loopEnd.pop_back();
					}
					else if (loopEnd.back() == "end forall")
					{
						if (CUtil::FindKeyword(tmp, "endforall", start, end, false) != string::npos)
							loopEnd.pop_back();
					}
				}
			}
开发者ID:XiangyuLi926,项目名称:2016SummerUCCProject,代码行数:67,代码来源:CFortranCounter.cpp

示例14: LSLOC

/*!
* Extracts and stores logical lines of code.
* Determines and extract logical SLOC to place in the result variable
* using addSLOC function. Each time the addSLOC function is called,
* a new logical SLOC is added. This function assumes that the directive
* is handled before it is called.
*
* \param result counter results
* \param line processed physical line of code
* \param lineBak original physical line of code
* \param strLSLOC processed logical string
* \param strLSLOCBak original logical string
* \param paren_cnt count of parenthesis
* \param forflag found for flag
* \param found_forifwhile found for, if, or while flag
* \param found_while found while flag
* \param prev_char previous character
* \param data_continue continuation of a data declaration line
* \param temp_lines tracks physical line count
* \param phys_exec_lines number of physical executable lines
* \param phys_data_lines number of physical data lines
* \param openBrackets number of open brackets (no matching close bracket)
* \param loopLevel nested loop level
*/
void CPerlCounter::LSLOC(results* result, string line, size_t lineNumber, string lineBak, string &strLSLOC, string &strLSLOCBak, unsigned int &paren_cnt,
	bool &forflag, bool &found_forifwhile, bool &found_while, char &prev_char, bool &data_continue,
	unsigned int &temp_lines, unsigned int &phys_exec_lines, unsigned int &phys_data_lines,
	unsigned int &openBrackets, StringVector &loopLevel)
{
	size_t start = 0; // starting index of the working string
	size_t i = 0, strSize, pos;
	bool do_boolean, trunc_flag = false;
	string exclude = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
	unsigned int cnt = 0;
	unsigned int loopCnt = 0;
	StringVector::iterator lit;
	string tmp = CUtil::TrimString(strLSLOC);
	string tmp2;

	// check for the keyword do
	do_boolean = (CUtil::FindKeyword(tmp, "do") == tmp.length() - 2);

	// check the entire line for SLOC present in it
	while (i < line.length())
	{
		if (line[i] == ';' || line[i] == '{')
		{
			// LSLOC terminators
			// ';' any valid perl command ends with a ';' terminator
			// do statements start with a '{' and ends with '}'

			if (line[i] == ';' && paren_cnt > 0)
			{
				// for a 'for' statement counter is incremented.
				i++;
				continue;
			}

			// record open bracket for nested loop processing
			if (print_cmplx)
			{
				if (line[i] == '{')
				{
					openBrackets++;
					if ((unsigned int)loopLevel.size() < openBrackets)
						loopLevel.push_back("");
				}
				else
				{
					if ((unsigned int)loopLevel.size() > openBrackets && openBrackets > 0)
						loopLevel.pop_back();
				}
			}

			if (found_while && found_forifwhile)
			{
				found_while = false;
				found_forifwhile = false;
				start = i + 1;
				i++;
				continue;
			}

			if (line[i] == '{')
			{
				// case for(...); and if (...) {
				// these specials are handled
				if (found_forifwhile)
				{
					found_forifwhile = false;
					start = i + 1;
					i++;
					continue;
				}

				// check if 'do' precedes '{'
				if (!do_boolean)
				{
					// find for 'do' in string before tmp string
					tmp = CUtil::TrimString(line.substr(start, i - start));
//.........这里部分代码省略.........
开发者ID:XiangyuLi926,项目名称:2016SummerUCCProject,代码行数:101,代码来源:CPerlCounter.cpp


注:本文中的StringVector::pop_back方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。