void TypeRegistry::collect_pure_methods(const TypeDesc &td, FunctionList &fl) const
{
    for (BaseTypeList::const_iterator i=td.base_types.begin(); i!=td.base_types.end(); ++i)
    {
        const TypeDesc *base = findTypeDescription(i->name);
        if (base)
            collect_pure_methods(*base, fl);
    }

    FunctionList methods;
    std::copy(td.methods.begin(), td.methods.end(), std::back_inserter(methods));
    std::copy(td.prot_methods.begin(), td.prot_methods.end(), std::back_inserter(methods));
    std::copy(td.priv_methods.begin(), td.priv_methods.end(), std::back_inserter(methods));

    for (FunctionList::const_iterator i=methods.begin(); i!=methods.end(); ++i)
    {
        if (i->is_pure_virtual)
        {
            fl.push_back(*i);
        }
        else
        {
            for (FunctionList::iterator j=fl.begin(); j!=fl.end();)
            {
                if (j->get_signature() == i->get_signature())
                {
                    fl.erase(j);
                }
                else
                    ++j;
            }
        }
    }
}
Esempio n. 2
0
	/* call function */
	Value Object::call (const std::string& function,
	                    const List& params) const
	{
		FunctionList list = mClass->getFunctions (function);
		
		/* no function found */
		if (list.empty())
			throw std::runtime_error (
					"Cannot find the function '" + function + "' in the class '"
					+ mClass->getName() + "'.");
		
		
		FunctionList::iterator iter;
		
		/* find a function which can handle the parameters */
		for (iter = list.begin(); iter != list.end(); ++iter)
		{
			Function* func = *iter;
			
			/* found match, execute the function */
			if (func->getType()->checkParamTypes (params))
				return func->call (params);
		}
		
		
		/* no capable function found */
		throw std::runtime_error (
				"Cannot find a function capable of handling the provided "
				"parameters");
	}
void QuickOpenFunctionDialog::gotoFile( QString name )
{
        FunctionModel *fmodel;
        FunctionList funcList;
        FunctionDom fdom;

        for( FunctionList::ConstIterator it = m_functionDefList.begin() ; it!=m_functionDefList.end() ; ++it ){
                fdom = *it;
                fmodel = fdom.data();
                if( fmodel->name() == name ){
                        funcList.append( fdom );
                }
        }
        if( funcList.count() == 1 ){
                fdom = funcList.first();
                fmodel = fdom.data();
                QString fileNameStr = fmodel->fileName();
                int startline, startcol;
                fmodel->getStartPosition( &startline, &startcol );
                m_part->partController()->editDocument( KURL( fileNameStr), startline, startcol );
                selectClassViewItem( ItemDom(&(*fmodel)) );

        }else if( funcList.count() > 1 ){
                QString fileStr;

                QuickOpenFunctionChooseForm fdlg( this, name.ascii() );

                for( FunctionList::Iterator it = funcList.begin() ; it!=funcList.end() ; ++it ){
                        fmodel = (*it).data();

                        fdlg.argBox->insertItem( m_part->languageSupport()->formatModelItem(fmodel) +
                                (fmodel->scope().isEmpty() ? "" : "   (in " + fmodel->scope().join("::") + ")"));
                        fileStr = KURL( fmodel->fileName() ).fileName();
                        KURL full_url( fmodel->fileName() );
                        KURL base_url( part()->project()->projectDirectory()+"/" );
                        fdlg.setRelativePath(fdlg.fileBox->count(),
                            KURL::relativeURL( base_url, full_url ));
                        fdlg.fileBox->insertItem(fileStr);
                }
                if( fdlg.exec() ){
                        int id = fdlg.argBox->currentItem();
                        if( id>-1 && id < (int) funcList.count() ){
                                FunctionModel *model = funcList[id].data();
                                int line, col;
                                model->getStartPosition( &line, &col );
                                selectClassViewItem( ItemDom(&(*model)) );
                                QString fileNameStr = model->fileName();
                                m_part->partController()->editDocument( KURL(fileNameStr), line );
                        }
                }
        }
        else{
                KMessageBox::error( this, i18n("Error: cannot find matching name function.") );
        }

        accept();
}
void SerialPlugIn::RemoveDMFunctions( void )
{
	FunctionList::const_iterator functionPtr;

	for(	functionPtr = fFunctionList.begin(); 
			functionPtr != fFunctionList.end(); 
			++functionPtr )
	{
		RemoveFunction( *functionPtr );
	}
}
Esempio n. 5
0
void refreshFunctions(ClassViewPart *part, KComboView *view, const ClassDom & dom)
{
    view->clear();

    view->setCurrentText(EmptyFunctions);
    FunctionList functions = dom->functionList();
    for (FunctionList::const_iterator it = functions.begin(); it != functions.end(); ++it)
    {
        FunctionItem *item = new FunctionItem(part, view->listView(), part->languageSupport()->formatModelItem(*it, true), *it);
        view->addItem(item);
        item->setOpen(true);
    }
}
Esempio n. 6
0
void testFuncParser(char *buf)
{
    printf("===== Testing function parser ======\n");
//	time_t start = GetTickCount();
    FunctionList li;
    //fflush(stdout);
    std::map<std::string, std::string> ignoreTokens;
    get_functions(buf, li, ignoreTokens);
//	time_t end = GetTickCount();
    for (FunctionList::iterator iter = li.begin(); iter != li.end(); iter++) {
        //test the var parser on the function argument list:
        clFunction f = (*iter);
        f.Print();
        //testVarParser((char*)f.m_signature.c_str());
        printf("%s\n", f.m_name.c_str());
    }

//	printf("total time: %d\n", end-start);
    printf("matches found: %d\n", li.size());
}
Esempio n. 7
0
void refreshFunctions(ClassViewPart *part, KComboView *view, const QString & dom)
{
    view->clear();

    view->setCurrentText(EmptyFunctions);
    NamespaceDom nsdom;
    if (dom == "::")
        nsdom = part->codeModel()->globalNamespace();
    else
    {
        nsdom = namespaceByName(part->codeModel()->globalNamespace(), dom);
        if (!nsdom)
            return;
    }
    FunctionList functions = nsdom->functionList();
    for (FunctionList::const_iterator it = functions.begin(); it != functions.end(); ++it)
    {
        FunctionItem *item = new FunctionItem(part, view->listView(), part->languageSupport()->formatModelItem(*it, true), *it);
        view->addItem(item);
        item->setOpen(true);
    }
}
Esempio n. 8
0
AddMethodDialog::AddMethodDialog( CppSupportPart* cppSupport, ClassDom klass,
                                  QWidget* parent, const char* name, bool modal, WFlags fl )
: AddMethodDialogBase( parent, name, modal, fl ), m_cppSupport( cppSupport ), m_klass( klass ), m_count( 0 )
{
	QString fileName = m_klass->fileName();

	access->insertStringList( QStringList() << "Public" << "Protected" << "Private" << "Signals" <<
	                          "Public Slots" << "Protected Slots" << "Private Slots" );

	storage->insertStringList( QStringList() << "Normal" << "Static" << "Virtual" << "Pure Virtual" << "Friend" );

	// setup sourceFile combo
	QMap<QString, bool> m;
#if 0 /// \FIXME ROBE

	FunctionList l = m_klass->functionList();
	{
		for ( FunctionList::Iterator it = l.begin(); it != l.end(); ++it )
		{
			if ( ( *it ) ->hasImplementation() )
				m.insert( ( *it ) ->implementedInFile(), true );
		}
	}
#endif

	{
		QStringList headers = QStringList::split( ",", "h,H,hh,hxx,hpp,inl,tlh,diff,ui.h" );
		QStringList fileList;
		QMap<QString, bool>::Iterator it = m.begin();
		while ( it != m.end() )
		{
			QString ext = QFileInfo( it.key() ).extension();
			if ( !headers.contains( ext ) )
				sourceFile->insertItem( it.key() );
			++it;
		}

		if ( sourceFile->count() == 0 )
		{
			QFileInfo info( fileName );
			QString impl = DomUtil::readEntry( *cppSupport->projectDom(), "/cppsupportpart/filetemplates/implementationsuffix", "cpp" );
			sourceFile->insertItem( info.dirPath( true ) + "/" + info.baseName() + impl );
		}
	}

	returnType->setAutoCompletion( true );
	returnType->insertStringList( QStringList()
	                              << "void"
	                              << "char"
	                              << "wchar_t"
	                              << "bool"
	                              << "short"
	                              << "int"
	                              << "long"
	                              << "signed"
	                              << "unsigned"
	                              << "float"
	                              << "double" );

	returnType->insertStringList( typeNameList( m_cppSupport->codeModel() ) );

	updateGUI();
	addMethod();
}
Esempio n. 9
0
void AddMethodDialog::accept()
{
	m_cppSupport->partController() ->editDocument( KURL( m_klass->fileName() ) );
	KTextEditor::EditInterface* editIface = dynamic_cast<KTextEditor::EditInterface*>( m_cppSupport->partController() ->activePart() );
	if ( !editIface )
	{
		/// @todo show messagebox
		QDialog::accept();
		return ;
	}

	int line, column;
	m_klass->getEndPosition( &line, &column );

	// compute the insertion point map
	QMap<QString, QPair<int, int> > points;
	QStringList accessList;

	const FunctionList functionList = m_klass->functionList();
	for ( FunctionList::ConstIterator it = functionList.begin(); it != functionList.end(); ++it )
	{
		int funEndLine, funEndColumn;
		( *it ) ->getEndPosition( &funEndLine, &funEndColumn );
		QString access = accessID( *it );
		QPair<int, int> funEndPoint = qMakePair( funEndLine, funEndColumn );

		if ( !points.contains( access ) || points[ access ] < funEndPoint )
		{
			accessList.remove( access );
			accessList.push_back( access ); // move 'access' at the end of the list

			points[ access ] = funEndPoint;
		}
	}

	int insertedLine = 0;

	accessList += newAccessList( accessList );

	for ( QStringList::iterator it = accessList.begin(); it != accessList.end(); ++it )
	{
		QListViewItem* item = methods->firstChild();
		while ( item )
		{
			QListViewItem * currentItem = item;

			item = item->nextSibling();

			if ( currentItem->text( 1 ) != *it )
				continue;

			QString access = ( *it ).lower();

			bool isInline = currentItem->text( 0 ) == "True";
			QString str = isInline ? functionDefinition( currentItem ) : functionDeclaration( currentItem );

			QPair<int, int> pt;
			if ( points.contains( *it ) )
			{
				pt = points[ *it ];
			}
			else
			{
			str.prepend( access + ":\n" );
				points[ *it ] = qMakePair( line - 1, 0 );
				pt = points[ *it ]; // end of class declaration
			}

			editIface->insertText( pt.first + insertedLine + 1, 0 /*pt.second*/, str );
			insertedLine += str.contains( QChar( '\n' ) );
		}
	}

	m_cppSupport->backgroundParser() ->addFile( m_klass->fileName() );

	QString str;
	QListViewItem* item = methods->firstChild();
	while ( item )
	{
		QListViewItem * currentItem = item;

		item = item->nextSibling();

		QString str = functionDefinition( currentItem );
		if ( str.isEmpty() )
			continue;

		QString implementationFile = currentItem->text( 5 );
		if ( currentItem->text( 0 ) == "True" )
			implementationFile = m_klass->fileName();

		QFileInfo fileInfo( implementationFile );
		if ( !QFile::exists( fileInfo.absFilePath() ) )
		{
			if ( KDevCreateFile * createFileSupp = m_cppSupport->extension<KDevCreateFile>( "KDevelop/CreateFile" ) )
				createFileSupp->createNewFile( fileInfo.extension(), fileInfo.dirPath( true ), fileInfo.baseName() );
		}

		m_cppSupport->partController() ->editDocument( KURL( implementationFile ) );
		editIface = dynamic_cast<KTextEditor::EditInterface*>( m_cppSupport->partController() ->activePart() );
		if ( !editIface )
			continue;

		bool isInline = currentItem->text( 0 ) == "True";
		if ( !isInline )
		{
			editIface->insertLine( editIface->numLines(), QString::fromLatin1( "" ) );
			editIface->insertText( editIface->numLines() - 1, 0, str );
			m_cppSupport->backgroundParser() ->addFile( implementationFile );
		}
	}

	QDialog::accept();
}