summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorGergo Mocsi <gmocsi91@gmail.com>2013-06-21 14:10:31 +0200
committerGergo Mocsi <gmocsi91@gmail.com>2013-09-02 18:16:42 +0200
commit025e7ff3e16650097097b6a17cd259170979ef3c (patch)
tree48dead1451a86797889d73a347048418faceb9a7 /basic
parentf97d794654cbf80afa0e4a60cda8147e94c11908 (diff)
GSOC work week 2, getting infromation from variables and print on terminal
This is an early version. I use the BASIC parser to parse the source, then the infromation is extracted from the symbol table built by parser. Error reporting is suppressed, beacuse it is not needed fro code completition. I placed my function inside SbModule, and created a struct called CodeCompletitionData, which holds the object's name, it's parent, and it's type name. This function, SbMethod::GetCodeCompleteDataFromParse() is called from Basic IDE's Notify function, which updates a cache(actually, reassigns a viariable :) ). Later, in the EditorWindow::KeyInput function there is a check wheteher dot key is pressed. After that, the actual variable (or word) is being looked up in the vector that holds code completition data. And finally, if it is found, it's methods are printed on the terminal. Change-Id: Idaf19baa8f720b8b117a76dc3cc2f90dd04fd155
Diffstat (limited to 'basic')
-rw-r--r--basic/source/classes/sb.cxx1
-rw-r--r--basic/source/classes/sbxmod.cxx47
-rw-r--r--basic/source/comp/dim.cxx2
-rw-r--r--basic/source/comp/parser.cxx1
-rw-r--r--basic/source/comp/sbcomp.cxx2
5 files changed, 52 insertions, 1 deletions
diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx
index 298712372ccd..3bd3fd60ce84 100644
--- a/basic/source/classes/sb.cxx
+++ b/basic/source/classes/sb.cxx
@@ -50,6 +50,7 @@
#include <com/sun/star/script/ModuleType.hpp>
#include <com/sun/star/script/ModuleInfo.hpp>
+#include <svtools/miscopt.hxx>
using namespace ::com::sun::star::script;
TYPEINIT1(StarBASIC,SbxObject)
diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx
index 28d10e290b01..c5608a877fc7 100644
--- a/basic/source/classes/sbxmod.cxx
+++ b/basic/source/classes/sbxmod.cxx
@@ -83,6 +83,7 @@ using namespace com::sun::star::uno;
#include <com/sun/star/awt/XControl.hpp>
#include <comphelper/anytostring.hxx>
#include <ooo/vba/VbQueryClose.hpp>
+#include "sbcomp.hxx"
typedef ::cppu::WeakImplHelper1< XInvocation > DocObjectWrapper_BASE;
typedef ::std::map< sal_Int16, Any, ::std::less< sal_Int16 > > OutParamMap;
@@ -1776,6 +1777,52 @@ IMPL_LINK( ErrorHdlResetter, BasicErrorHdl, StarBASIC *, /*pBasic*/)
return 0;
}
+
+std::vector< CodeCompleteData > SbModule::GetCodeCompleteDataFromParse()
+{
+ ErrorHdlResetter aErrHdl;
+ StarBASIC* pBasic = PTR_CAST(StarBASIC,GetParent());
+ SbxBase::ResetError();
+ SbModule* pOld = GetSbData()->pCompMod;
+ GetSbData()->pCompMod = this;
+
+ SbiParser* pParser = new SbiParser( (StarBASIC*) GetParent(), this );
+
+ while( pParser->Parse() ) {}
+ SbiSymPool* pPool = pParser->pPool;
+ std::vector< CodeCompleteData > aRet;
+ for( sal_uInt16 i = 0; i < pPool->GetSize(); ++i )
+ {
+ SbiSymDef* pSymDef = pPool->Get(i);
+ if( pSymDef->GetType() == SbxOBJECT )
+ {
+ CodeCompleteData aCodeCompleteData;
+ aCodeCompleteData.sVarName = pSymDef->GetName();
+ aCodeCompleteData.sVarParent = OUString("");
+ aCodeCompleteData.sVarType = pParser->aGblStrings.Find( pSymDef->GetTypeId() );
+ if(!aCodeCompleteData.sVarType.isEmpty())
+ aRet.push_back(aCodeCompleteData);
+ }
+
+ SbiSymPool& pChildPool = pSymDef->GetPool();
+ for(sal_uInt16 j = 0; j < pChildPool.GetSize(); ++j )
+ {
+ CodeCompleteData aCodeCompleteData;
+ SbiSymDef* pChildSymDef = pChildPool.Get(j);
+ if( pChildSymDef->GetType() == SbxOBJECT )
+ {
+ aCodeCompleteData.sVarName = pChildSymDef->GetName();
+ aCodeCompleteData.sVarParent = pSymDef->GetName();
+ aCodeCompleteData.sVarType = pParser->aGblStrings.Find( pChildSymDef->GetTypeId() );
+ if(!aCodeCompleteData.sVarType.isEmpty())
+ aRet.push_back(aCodeCompleteData);
+ }
+ }
+ }
+ delete pParser;
+ return aRet;
+}
+
bool SbModule::HasExeCode()
{
// And empty Image always has the Global Chain set up
diff --git a/basic/source/comp/dim.cxx b/basic/source/comp/dim.cxx
index 609436944b63..8da4d1e13c3c 100644
--- a/basic/source/comp/dim.cxx
+++ b/basic/source/comp/dim.cxx
@@ -307,6 +307,8 @@ void SbiParser::DefVar( SbiOpcode eOp, bool bStatic )
bool bDefined = false;
while( ( pDef = VarDecl( &pDim, bStatic, bConst ) ) != NULL )
{
+ /*fprintf(stderr, "Actual sub: \n");
+ fprintf(stderr, "Symbol name: %s\n",OUStringToOString(pDef->GetName(),RTL_TEXTENCODING_UTF8).getStr());*/
EnableErrors();
// search variable:
if( bSwitchPool )
diff --git a/basic/source/comp/parser.cxx b/basic/source/comp/parser.cxx
index d61f33444a7b..018b2938ee84 100644
--- a/basic/source/comp/parser.cxx
+++ b/basic/source/comp/parser.cxx
@@ -20,6 +20,7 @@
#include <basic/sbx.hxx>
#include "sbcomp.hxx"
#include <com/sun/star/script/ModuleType.hpp>
+#include <svtools/miscopt.hxx>
struct SbiParseStack { // "Stack" for statement-blocks
SbiParseStack* pNext; // Chain
diff --git a/basic/source/comp/sbcomp.cxx b/basic/source/comp/sbcomp.cxx
index 32cdabc7067b..e4d95f1dfb85 100644
--- a/basic/source/comp/sbcomp.cxx
+++ b/basic/source/comp/sbcomp.cxx
@@ -22,6 +22,7 @@
#include "sbcomp.hxx"
#include "image.hxx"
#include <basic/sbobjmod.hxx>
+#include <svtools/miscopt.hxx>
#include <stdio.h>
// To activate tracing enable in sbtrace.hxx
@@ -993,5 +994,4 @@ sal_Bool SbModule::Compile()
return bRet;
}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */