basctl/source/basicide/baside2b.cxx | 36 ++--------- basctl/source/basicide/codecompleteoptionsdlg.cxx | 5 - basic/source/classes/codecompletecache.cxx | 68 ++++++++++++++++------ basic/source/classes/sbxmod.cxx | 41 ++++++++----- include/basic/codecompletecache.hxx | 11 +-- include/basic/sbmod.hxx | 3 6 files changed, 95 insertions(+), 69 deletions(-)
New commits: commit fd35319cbf96e215cf52db70d947ff0b5cf96948 Author: Gergo Mocsi <gmocs...@gmail.com> Date: Wed Jul 24 17:27:02 2013 +0200 GSOC work, cache implementation fix, code fixes The CodeCompleteDataCache got a new implementation: global variables are stored separately. The "static const" OUString-s were removed from the class. Data extraction is only done when pressing the dot key. Change-Id: I3ff94c0c6eabe328761336d4c74744eb7efc6056 diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx index 8c5f6212..d561997 100644 --- a/basctl/source/basicide/baside2b.cxx +++ b/basctl/source/basicide/baside2b.cxx @@ -502,10 +502,11 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt ) if( rKEvt.GetKeyCode().GetCode() == KEY_POINT && CodeCompleteOptions::IsCodeCompleteOn() ) { rModulWindow.UpdateModule(); + rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse(aCodeCompleteCache); TextSelection aSel = GetEditView()->GetSelection(); sal_uLong nLine = aSel.GetStart().GetPara(); OUString aLine( pEditEngine->GetText( nLine ) ); // the line being modified - OUString sActSub = GetActualSubName( nLine ); + //OUString sActSub = GetActualSubName( nLine ); std::vector< OUString > aVect; HighlightPortions aPortions; @@ -517,9 +518,7 @@ void EditorWindow::KeyInput( const KeyEvent& rKEvt ) aVect.push_back( aLine.copy(r.nBegin, r.nEnd - r.nBegin) ); } OUString sBaseName = aVect[0];//variable name - OUString sVarType = aCodeCompleteCache.GetVariableType(sBaseName, CodeCompleteDataCache::GLOB_KEY); - if( sVarType == CodeCompleteDataCache::NOT_FOUND ) - sVarType = aCodeCompleteCache.GetVariableType(sBaseName, sActSub); + OUString sVarType = aCodeCompleteCache.GetVarType( sBaseName ); Reference< lang::XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory(), UNO_SET_THROW ); Reference< reflection::XIdlReflection > xRefl( xFactory->createInstance("com.sun.star.reflection.CoreReflection"), UNO_QUERY_THROW ); @@ -827,20 +826,10 @@ void EditorWindow::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) { ParagraphInsertedDeleted( rTextHint.GetValue(), true ); DoDelayedSyntaxHighlight( rTextHint.GetValue() ); - if( CodeCompleteOptions::IsCodeCompleteOn() ) - { - rModulWindow.UpdateModule(); - aCodeCompleteCache.SetVars(rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse().GetVars()); - } } else if( rTextHint.GetId() == TEXT_HINT_PARAREMOVED ) { ParagraphInsertedDeleted( rTextHint.GetValue(), false ); - if( CodeCompleteOptions::IsCodeCompleteOn() ) - { - rModulWindow.UpdateModule(); - aCodeCompleteCache.SetVars(rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse().GetVars()); - } } else if( rTextHint.GetId() == TEXT_HINT_PARACONTENTCHANGED ) { @@ -854,11 +843,6 @@ void EditorWindow::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) pBindings->Invalidate( SID_COPY ); } } - else if( rTextHint.GetId() == TEXT_HINT_MODIFIED && CodeCompleteOptions::IsCodeCompleteOn() ) - { - rModulWindow.UpdateModule(); - aCodeCompleteCache.SetVars(rModulWindow.GetSbModule()->GetCodeCompleteDataFromParse().GetVars()); - } } } @@ -876,12 +860,11 @@ OUString EditorWindow::GetActualSubName( sal_uLong nLine ) pMeth->GetLineRange(l1,l2); if( (l1 <= nLine+1) && (nLine+1 <= l2) ) { - //std::cerr << "sName: " << sName << std::endl; return sName; } } } - return CodeCompleteDataCache::GLOB_KEY; + return OUString(""); } void EditorWindow::SetScrollBarRanges() @@ -2374,7 +2357,7 @@ IMPL_LINK_NOARG(CodeCompleteListBox, ImplDoubleClickHdl) void CodeCompleteListBox::InsertSelectedEntry() { - if( aFuncBuffer.toString() != OUString("") ) + if( !aFuncBuffer.toString().isEmpty() ) { // if the user typed in something: remove, and insert TextPaM aEnd(pCodeCompleteWindow->aTextSelection.GetEnd().GetPara(), pCodeCompleteWindow->GetTextSelection().GetEnd().GetIndex() + aFuncBuffer.getLength()); @@ -2382,7 +2365,7 @@ void CodeCompleteListBox::InsertSelectedEntry() pCodeCompleteWindow->pParent->GetEditView()->SetSelection(TextSelection(aStart, aEnd)); pCodeCompleteWindow->pParent->GetEditView()->DeleteSelected(); - if( GetEntry( GetSelectEntryPos() ) != OUString("") ) + if( !((OUString) GetEntry( GetSelectEntryPos() )).isEmpty() ) {//if the user selected something pCodeCompleteWindow->pParent->GetEditView()->InsertText( (OUString) GetEntry(GetSelectEntryPos()), sal_True ); pCodeCompleteWindow->Hide(); @@ -2398,7 +2381,7 @@ void CodeCompleteListBox::InsertSelectedEntry() } else { - if( GetEntry( GetSelectEntryPos() ) != OUString("") ) + if( !((OUString) GetEntry( GetSelectEntryPos() )).isEmpty() ) {//if the user selected something pCodeCompleteWindow->pParent->GetEditView()->InsertText( (OUString) GetEntry(GetSelectEntryPos()), sal_True ); pCodeCompleteWindow->Hide(); @@ -2427,9 +2410,6 @@ long CodeCompleteListBox::PreNotify( NotifyEvent& rNEvt ) { case KEY_ESCAPE: // hide, do nothing pCodeCompleteWindow->ClearAndHide(); - /*pCodeCompleteWindow->Hide(); - pCodeCompleteWindow->pParent->GetEditView()->SetSelection( pCodeCompleteWindow->pParent->GetEditView()->CursorEndOfLine(pCodeCompleteWindow->GetTextSelection().GetStart()) ); - //pCodeCompleteWindow->pParent->GrabFocus();*/ return 0; case KEY_TAB: case KEY_SPACE: /* space, tab the user probably have typed in the whole @@ -2522,7 +2502,7 @@ void CodeCompleteWindow::ResizeListBox() aLongestEntry = pListBox->GetEntry( i ); } - Size aSize = pListBox->GetOptimalSize(); + Size aSize = pListBox->CalcSize( aLongestEntry.getLength(), std::min( (sal_uInt16) 4, pListBox->GetEntryCount()) ); const Font& aFont = pListBox->GetUnzoomedControlPointFont(); aSize.setHeight( aFont.GetSize().getHeight() * 16 ); diff --git a/basctl/source/basicide/codecompleteoptionsdlg.cxx b/basctl/source/basicide/codecompleteoptionsdlg.cxx index a948ab6..96d1ca7 100644 --- a/basctl/source/basicide/codecompleteoptionsdlg.cxx +++ b/basctl/source/basicide/codecompleteoptionsdlg.cxx @@ -40,9 +40,9 @@ CodeCompleteOptionsDlg::CodeCompleteOptionsDlg( Window* pWindow ) pOkBtn->SetClickHdl( LINK( this, CodeCompleteOptionsDlg, OkHdl ) ); pCancelBtn->SetClickHdl( LINK( this, CodeCompleteOptionsDlg, CancelHdl ) ); - pCodeCompleteChk->Check(CodeCompleteOptions::IsCodeCompleteOn()); //set it on, if needed + pCodeCompleteChk->Check( CodeCompleteOptions::IsCodeCompleteOn() ); + pAutocloseProcChk->Check( CodeCompleteOptions::IsProcedureAutoCompleteOn() ); - pAutocloseProcChk->Enable( false ); pAutocloseBracesChk->Enable( false ); pAutocloseQuotesChk->Enable( false ); } @@ -54,6 +54,7 @@ CodeCompleteOptionsDlg::~CodeCompleteOptionsDlg() IMPL_LINK_NOARG(CodeCompleteOptionsDlg, OkHdl) { CodeCompleteOptions::SetCodeCompleteOn( pCodeCompleteChk->IsChecked() ); + CodeCompleteOptions::SetProcedureAutoCompleteOn( pCodeCompleteChk->IsChecked() ); Close(); return 0; } diff --git a/basic/source/classes/codecompletecache.cxx b/basic/source/classes/codecompletecache.cxx index 3898eb2..cb5d4db 100644 --- a/basic/source/classes/codecompletecache.cxx +++ b/basic/source/classes/codecompletecache.cxx @@ -21,9 +21,6 @@ #include <iostream> #include <rtl/instance.hxx> -const OUString CodeCompleteDataCache::GLOB_KEY = OUString("global key"); -const OUString CodeCompleteDataCache::NOT_FOUND = OUString("not found"); - namespace { class theCodeCompleteOptions: public ::rtl::Static< CodeCompleteOptions, theCodeCompleteOptions >{}; @@ -62,6 +59,12 @@ void CodeCompleteOptions::SetProcedureAutoCompleteOn( const bool& b ) std::ostream& operator<< (std::ostream& aStream, const CodeCompleteDataCache& aCache) { + aStream << "Global variables" << std::endl; + for(CodeCompleteVarTypes::const_iterator aIt = aCache.aGlobalVars.begin(); aIt != aCache.aGlobalVars.end(); ++aIt ) + { + aStream << aIt->first << "," << aIt->second << std::endl; + } + aStream << "Local variables" << std::endl; for( CodeCompleteVarScopes::const_iterator aIt = aCache.aVarScopes.begin(); aIt != aCache.aVarScopes.end(); ++aIt ) { aStream << aIt->first << std::endl; @@ -80,32 +83,61 @@ const CodeCompleteVarScopes& CodeCompleteDataCache::GetVars() const return aVarScopes; } -void CodeCompleteDataCache::InsertProcedure( const OUString& sProcName, const CodeCompleteVarTypes& aVarTypes ) -{ - aVarScopes.insert( CodeCompleteVarScopes::value_type(sProcName, aVarTypes) ); -} void CodeCompleteDataCache::SetVars( const CodeCompleteVarScopes& aScopes ) { aVarScopes = aScopes; } -OUString CodeCompleteDataCache::GetVariableType( const OUString& sVarName, const OUString& sProcName ) const +void CodeCompleteDataCache::print() const { - CodeCompleteVarScopes::const_iterator aIt = aVarScopes.find( sProcName ); - if( aIt == aVarScopes.end() )//procedure does not exist - return CodeCompleteDataCache::NOT_FOUND; + std::cerr << *this << std::endl; +} + +void CodeCompleteDataCache::Clear() +{ + aVarScopes.clear(); +} + +void CodeCompleteDataCache::InsertGlobalVar( const OUString& sVarName, const OUString& sVarType ) +{ + aGlobalVars.insert( CodeCompleteVarTypes::value_type(sVarName, sVarType) ); +} - CodeCompleteVarTypes aVarTypes = aIt->second; - CodeCompleteVarTypes::const_iterator aOtherIt = aVarTypes.find( sVarName ); - if( aOtherIt == aVarTypes.end() ) - return CodeCompleteDataCache::NOT_FOUND; +void CodeCompleteDataCache::InsertLocalVar( const OUString& sProcName, const OUString& sVarName, const OUString& sVarType ) +{ + CodeCompleteVarScopes::const_iterator aIt = aVarScopes.find( sProcName ); + if( aIt == aVarScopes.end() ) //new procedure + { + CodeCompleteVarTypes aTypes; + aTypes.insert( CodeCompleteVarTypes::value_type(sVarName, sVarType) ); + aVarScopes.insert( CodeCompleteVarScopes::value_type(sProcName, aTypes) ); + } else - return aOtherIt->second; + { + CodeCompleteVarTypes aTypes = aVarScopes[ sProcName ]; + aTypes.insert( CodeCompleteVarTypes::value_type(sVarName, sVarType) ); + aVarScopes[ sProcName ] = aTypes; + } } -void CodeCompleteDataCache::print() const +OUString CodeCompleteDataCache::GetVarType( const OUString& sVarName ) { - std::cerr << *this << std::endl; + for( CodeCompleteVarScopes::const_iterator aIt = aVarScopes.begin(); aIt != aVarScopes.end(); ++aIt ) + { + CodeCompleteVarTypes aTypes = aIt->second; + for( CodeCompleteVarTypes::const_iterator aOtherIt = aTypes.begin(); aOtherIt != aTypes.end(); ++aOtherIt ) + { + if( aOtherIt->first == sVarName ) + return aOtherIt->second; + } + } + //not a local, search global scope + for( CodeCompleteVarTypes::const_iterator aIt = aGlobalVars.begin(); aIt != aGlobalVars.end(); ++aIt ) + { + if( aIt->first == sVarName ) + return aIt->second; + } + return OUString(""); //not found } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx index cbe5886..694fbf3 100644 --- a/basic/source/classes/sbxmod.cxx +++ b/basic/source/classes/sbxmod.cxx @@ -90,9 +90,6 @@ typedef ::std::map< sal_Int16, Any, ::std::less< sal_Int16 > > OutParamMap; ::com::sun::star::uno::Any sbxToUnoValue( SbxVariable* pVar ); void unoToSbxValue( SbxVariable* pVar, const ::com::sun::star::uno::Any& aValue ); -/*const OUString CodeCompleteDataCache::GLOB_KEY = OUString("global key"); -const OUString CodeCompleteDataCache::NOT_FOUND = OUString("not found");*/ - class DocObjectWrapper : public DocObjectWrapper_BASE { Reference< XAggregation > m_xAggProxy; @@ -672,7 +669,6 @@ void SbModule::EndDefinitions( sal_Bool bNewState ) { if( p->bInvalid ) { - std::cerr << "invalid definition: " << p->GetName() << std::endl; pMethods->Remove( p ); } else @@ -941,12 +937,15 @@ void SbModule::SetSource32( const OUString& r ) } // Definition of the method SbMethod* pMeth = NULL; + OUString sMethName; if( eEndTok != NIL ) { sal_uInt16 nLine1 = aTok.GetLine(); if( aTok.Next() == SYMBOL ) { OUString aName_( aTok.GetSym() ); + //std::cerr << "method name: " << aName_ << std::endl; + sMethName = aName_; SbxDataType t = aTok.GetType(); if( t == SbxVARIANT && eEndTok == ENDSUB ) { @@ -970,12 +969,25 @@ void SbModule::SetSource32( const OUString& r ) if( aTok.Next() == eEndTok ) { pMeth->nLine2 = aTok.GetLine(); + //std::cerr << "there is end for "<< sMethName << std::endl; break; } } if( aTok.IsEof() ) { pMeth->nLine2 = aTok.GetLine(); + std::cerr << "EOF reached, no end for "<< sMethName <<", line " << aTok.GetLine() << std::endl; + //std::cerr << "write end to: " << aOUSource.getLength() / pMeth->nLine2 << std::endl; + sal_Int32 nPos=0; + sal_Int32 nCounter = 0; + std::cerr << "source length: " << aOUSource.getLength() << std::endl; + for(sal_uInt32 i=0; i < aOUSource.getLength() ; ++i) + { + nPos++; + if( aOUSource[i] == '\n' && nCounter != aTok.GetLine() ) + nCounter++; + } + std::cerr << "newline index: " << nPos << std::endl; } } } @@ -1783,9 +1795,8 @@ IMPL_LINK( ErrorHdlResetter, BasicErrorHdl, StarBASIC *, /*pBasic*/) return 0; } -CodeCompleteDataCache SbModule::GetCodeCompleteDataFromParse() +void SbModule::GetCodeCompleteDataFromParse(CodeCompleteDataCache& aCache) { - CodeCompleteDataCache aCache; ErrorHdlResetter aErrHdl; SbxBase::ResetError(); @@ -1794,7 +1805,8 @@ CodeCompleteDataCache SbModule::GetCodeCompleteDataFromParse() while( pParser->Parse() ) {} SbiSymPool* pPool = pParser->pPool; - CodeCompleteVarTypes aGlobVarTypes; + //CodeCompleteVarTypes aGlobVarTypes; + aCache.Clear(); for( sal_uInt16 i = 0; i < pPool->GetSize(); ++i ) { SbiSymDef* pSymDef = pPool->Get(i); @@ -1802,13 +1814,13 @@ CodeCompleteDataCache SbModule::GetCodeCompleteDataFromParse() { if( !pParser->aGblStrings.Find( pSymDef->GetTypeId() ).isEmpty() ) { - //std::cerr << "global " << pSymDef->GetName() << std::endl; - aGlobVarTypes.insert( CodeCompleteVarTypes::value_type( pSymDef->GetName(), pParser->aGblStrings.Find( pSymDef->GetTypeId() ) ) ); + //aGlobVarTypes.insert( CodeCompleteVarTypes::value_type( pSymDef->GetName(), pParser->aGblStrings.Find( pSymDef->GetTypeId() ) ) ); + aCache.InsertGlobalVar( pSymDef->GetName(), pParser->aGblStrings.Find(pSymDef->GetTypeId()) ); } } SbiSymPool& pChildPool = pSymDef->GetPool(); - CodeCompleteVarTypes aLocVarTypes; + //CodeCompleteVarTypes aLocVarTypes; for(sal_uInt16 j = 0; j < pChildPool.GetSize(); ++j ) { SbiSymDef* pChildSymDef = pChildPool.Get(j); @@ -1816,17 +1828,16 @@ CodeCompleteDataCache SbModule::GetCodeCompleteDataFromParse() { if( !pParser->aGblStrings.Find( pChildSymDef->GetTypeId() ).isEmpty() ) { - //std::cerr << "local " << pChildSymDef->GetName() << std::endl; - aLocVarTypes.insert( CodeCompleteVarTypes::value_type( pChildSymDef->GetName(), pParser->aGblStrings.Find( pChildSymDef->GetTypeId() ) ) ); + //aLocVarTypes.insert( CodeCompleteVarTypes::value_type( pChildSymDef->GetName(), pParser->aGblStrings.Find( pChildSymDef->GetTypeId() ) ) ); + aCache.InsertLocalVar( pSymDef->GetName(), pChildSymDef->GetName(), pParser->aGblStrings.Find(pChildSymDef->GetTypeId()) ); } } } - aCache.InsertProcedure( pSymDef->GetName(), aLocVarTypes ); + //aCache.InsertProcedure( pSymDef->GetName(), aLocVarTypes ); } - aCache.InsertProcedure( CodeCompleteDataCache::GLOB_KEY, aGlobVarTypes ); + //aCache.InsertProcedure( CodeCompleteDataCache::GLOB_KEY, aGlobVarTypes ); delete pParser; - return aCache; } SbxArrayRef SbModule::GetMethods() diff --git a/include/basic/codecompletecache.hxx b/include/basic/codecompletecache.hxx index 57ed673..480c3c1 100644 --- a/include/basic/codecompletecache.hxx +++ b/include/basic/codecompletecache.hxx @@ -33,6 +33,7 @@ typedef boost::unordered_map< OUString, OUString, OUStringHash > CodeCompleteVar typedef boost::unordered_map< OUString, CodeCompleteVarTypes, OUStringHash > CodeCompleteVarScopes; /* procedure, CodeCompleteVarTypes */ + class BASIC_DLLPUBLIC CodeCompleteOptions { /* @@ -63,11 +64,9 @@ class BASIC_DLLPUBLIC CodeCompleteDataCache * */ private: CodeCompleteVarScopes aVarScopes; + CodeCompleteVarTypes aGlobalVars; public: - static const OUString GLOB_KEY; - static const OUString NOT_FOUND; - CodeCompleteDataCache(){} virtual ~CodeCompleteDataCache(){} @@ -76,9 +75,11 @@ public: void SetVars( const CodeCompleteVarScopes& aScopes ); const CodeCompleteVarScopes& GetVars() const; - void InsertProcedure( const OUString& sProcName, const CodeCompleteVarTypes& aVarTypes ); - OUString GetVariableType( const OUString& sVarName, const OUString& sProcName ) const; + void InsertGlobalVar( const OUString& sVarName, const OUString& sVarType ); + void InsertLocalVar( const OUString& sProcName, const OUString& sVarName, const OUString& sVarType ); + OUString GetVarType( const OUString& sVarName ); void print() const; // wrapper for operator<<, prints to std::cerr + void Clear(); }; #endif // CODECOMPLETECACHE_H diff --git a/include/basic/sbmod.hxx b/include/basic/sbmod.hxx index 5a77cfb..b3e694b 100644 --- a/include/basic/sbmod.hxx +++ b/include/basic/sbmod.hxx @@ -152,7 +152,8 @@ public: void RemoveVars(); ::com::sun::star::uno::Reference< ::com::sun::star::script::XInvocation > GetUnoModule(); bool createCOMWrapperForIface( ::com::sun::star::uno::Any& o_rRetAny, SbClassModuleObject* pProxyClassModuleObject ); - CodeCompleteDataCache GetCodeCompleteDataFromParse(); + //CodeCompleteDataCache GetCodeCompleteDataFromParse(); + void GetCodeCompleteDataFromParse(CodeCompleteDataCache& aCache); SbxArrayRef GetMethods(); }; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits