summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorGergo Mocsi <gmocsi91@gmail.com>2013-07-24 17:27:02 +0200
committerGergo Mocsi <gmocsi91@gmail.com>2013-09-02 18:16:48 +0200
commitedcec5b1be9b224dbdfb4cd85c37148243f49389 (patch)
tree50a8afdb188079d03396df1dabbc43e1d1ec4b85 /basic
parent70ab744ccf047a90bee0506c6a60ade1935ece3d (diff)
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
Diffstat (limited to 'basic')
-rw-r--r--basic/source/classes/codecompletecache.cxx68
-rw-r--r--basic/source/classes/sbxmod.cxx41
2 files changed, 76 insertions, 33 deletions
diff --git a/basic/source/classes/codecompletecache.cxx b/basic/source/classes/codecompletecache.cxx
index 3898eb2b20ae..cb5d4dbff4f7 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 cbe5886640a6..694fbf338fe0 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()