summaryrefslogtreecommitdiff
path: root/basic/source/classes/codecompletecache.cxx
diff options
context:
space:
mode:
authorGergo Mocsi <gmocsi91@gmail.com>2013-07-24 17:27:02 +0200
committerGergo Mocsi <gmocsi91@gmail.com>2013-07-24 17:27:02 +0200
commitfd35319cbf96e215cf52db70d947ff0b5cf96948 (patch)
tree66fe50ea24117c90a44f75a3261e4449199d5d34 /basic/source/classes/codecompletecache.cxx
parentc4373b6e3b07bbd0d633499da4e1afd692d03889 (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/source/classes/codecompletecache.cxx')
-rw-r--r--basic/source/classes/codecompletecache.cxx68
1 files changed, 50 insertions, 18 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: */