Esempio n. 1
0
bool Parse::getScopeAndLocals(Scope * sc, const QString &expr, const QString &ident)
{
	// initialize scope if nothing better is found
	sc->scope = "";
	sc->localdef = "";

	/* create a tags file for `expr' with function names only.
	 * The function with the highest line number is our valid scope
	 * --sort=no, because tags generation probably faster, and
	 * so I just have to look for the last entry to find 'my' tag
	 */

	QString command =
	    ctagsCmdPath +
	    " --language-force=c++ --sort=no --fields=fKmnsz --c++-kinds=fn -o \"" +
	    smallTagsFilePath + "\" \"" + parsedFilePath + '\"';

	// I don't process any user input, so system() should be safe enough
	QProcess ctags;
	ctags.execute(command);
	QFile::remove (parsedFilePath);
	if (ctags.exitStatus() == QProcess::CrashExit)
		return false;

	/* find the last entry, this is our current scope */
	tagFileInfo info;
	tagFile *tfile = tagsOpen(smallTagsFilePath.toAscii(), &info);
	tagEntry entry;
	const char *scope = NULL;
	if (tfile && info.status.opened)
	{
		if (tagsFirst(tfile, &entry) == TagSuccess)
		{
			do
				scope = tagsField(&entry, "class");
			while (tagsNext(tfile, &entry) == TagSuccess);
		}
		tagsClose(tfile);
	}

	/* must be before the 'type = extract_type_qualifier()' code, which modifies scope */
	if (scope)
		sc->scope = scope;

	/* get local definition (if any) */
	if (ident!="")
	{
		QString type = extractTypeQualifier(expr, ident);
		if (type.length())
		{
			sc->localdef = type;
		}
		else
			sc->localdef = "";
	}

	QFile::remove (smallTagsFilePath);
	
	return true;
}
Esempio n. 2
0
static gboolean find_first(tagFile *tf, tagEntry *entry, const gchar *name, MatchType match_type)
{
	gboolean ret;

	if (match_type == MATCH_PATTERN)
		ret = tagsFirst(tf, entry) == TagSuccess;
	else
	{
		int options = TAG_IGNORECASE;

		options |= match_type == MATCH_PREFIX ? TAG_PARTIALMATCH : TAG_FULLMATCH;
		ret = tagsFind(tf, entry, name, options) == TagSuccess;
	}
	return ret;
}