pasha19
unread,Nov 6, 2009, 5:18:52 PM11/6/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to scintilla-interest
I am attempting an adaption (as in a new version cloned from lexSQL)
as a lexer primarily to support a specific flavor of SQL. My issue
may be a windows programming question more than a scintilla question.
I have created two stack objects (C++ classes) and two element classes
to support instruction (parsing) state and fold level calculation
statically allocated with 128 elements in each stack (probable
overkill) . After inserting two items into the InstStack object
(neither of which pushed Foldstack enties and deleting one the
application aborts with the following message in an area well outside
my code changes according to the debugger. Do I have an issue using C+
+ objects (and memory management from the lexer colorise function?
Can these objects be built earlier in the code and passed to the
function to avoid the windows limitations (suggestions of a suitable
location would be helpful but not required -- I assume the first C++
class I find tracing the colorize function call back should be a
suitable object for the requested purpose. I am an experienced
programmer but relatively new to windows and C++. PS suggestions
concerning errors in my C++ coding are not considered out of scope by
anyone that may notice them (I already correct a couple of ='s that
should have been =='s in this code and elsewhere.)
This appears to be the pertinent aspects of the error message
First-chance exception at 0x10173731 (SciLexer.dll) in
notepadPlus_Debug.exe: 0xC0000005: Access violation reading location
0xccccccce.
First-chance exception at 0x7c812afb in notepadPlus_Debug.exe:
Microsoft C++ exception: Win32AccessViolation at memory location
0x000d5e30..
First-chance exception at 0x1016f5b3 (SciLexer.dll) in
notepadPlus_Debug.exe: 0xC0000005: Access violation reading location
0xccccccc8.
First-chance exception at 0x7c812afb in notepadPlus_Debug.exe:
Microsoft C++ exception: Win32AccessViolation at memory location
0x000d4b88..
the code for the objects is as follows
// Scintilla source code edit control
/** @file inststack.h
** instruction state stack and additional stack to identify fold
information
**/
// Copyright 2009 by David Shuman
// The License.txt file describes the conditions under which this
software may be distributed.
#ifndef INSTSTACK_H
#define INSTSTACK_H
#include <assert.h>
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
const int StackSize = 128;
class FoldStackE {
public:
char type;
bool delay;
bool needHead;
int line;
int inst;
FoldStackE (int sz = 0) { init(0, sz); }
FoldStackE (const FoldStackE *array, int sz) { init(array, sz); }
FoldStackE (const FoldStackE&);
~FoldStackE () { };
FoldStackE& operator=(const FoldStackE&) { return *this; }
protected:
void init (const FoldStackE *array, int sz) {
type = ' ';
delay = false;
needHead = false;
line = 0;
inst = 0;
}
};
class FoldStack {
public:
FoldStack (int sz = StackSize) { init (0, sz); }
FoldStack (const FoldStackE *array, int sz) { init(array, sz); }
FoldStack (const FoldStack&);
~FoldStack () { delete [] fSE; };
int push (char pType, int pLine, int pInst) {
int rc = 0;
// purge pending delay before push
if (idx && fSE[idx].delay) { idx--; }
foldWhite = false;
if ((idx < StackSize) &&
((!idx) || (fSE[idx].line < pLine))) {
rc = ++idx;
fSE[idx].type = pType;
fSE[idx].delay = false;
fSE[idx].needHead = true;
fSE[idx].line = pLine;
fSE[idx].inst = pInst;
}
return rc;
}
int pop (char pType, int pFold, bool pDelay, int pLine) {
int rc = 0;
// purge pending delay before pop
if (idx && fSE[idx].delay) { idx--; }
if (idx && (fSE[idx].type = pType) && (idx == pFold)) {
if (fSE[idx].line == pLine) {
rc = idx--;
} else if (pDelay) {
fSE[idx].delay = pDelay;
rc = idx;
} else {
rc = idx--;
}
}
foldWhite = (idx && fSE[idx].delay);
return rc;
}
int getLine() { return fSE[idx].line; }
int getFold(bool pPurge) {
int rc = idx | SC_FOLDLEVELBASE;
// purge pending delays before insert
if (pPurge) {
if (idx && fSE[idx].delay) { idx--; }
}
return rc;
}
int getFoldWhite() { return foldWhite; }
bool getFoldHead() {
bool rc = fSE[idx].needHead;
fSE[idx].needHead = false;
return rc;
}
protected:
int idx;
bool foldWhite;
int size;
FoldStackE *fSE;
void init (const FoldStackE *fSE, int sz) {
idx = 0;
foldWhite = false;
size = sz;
fSE = new FoldStackE[size];
assert (fSE != 0);
}
};
class InstStackE {
public:
char type;
bool isState;
int line;
int fold;
InstStackE (int sz = 0) { init (0, sz); }
InstStackE (const InstStackE *array, int sz) { init(array, sz); }
InstStackE (const InstStackE&);
~InstStackE () { };
InstStackE& operator=(const InstStackE&) { return *this; }
protected:
void init (const InstStackE *array, int sz) {
type = ' ';
isState = false;
line = 0;
fold = 0;
}
};
class InstStack {
public:
InstStack (int sz = StackSize) { init (0, sz); }
InstStack (const InstStackE *array, int sz) { init(array, sz); }
InstStack (const InstStack&);
~InstStack () { delete [] iSE; };
int push(char pType, bool pIsState, int pLine, bool pFold) {
int rc = 0;
if (idx < StackSize) {
rc = ++idx;;
iSE[idx].type = pType;
iSE[idx].isState = pIsState;
iSE[idx].line = pLine;
if (pFold) {
iSE[idx].fold = fS.push(pType, pLine, idx);
} else {
iSE[idx].fold = 0;
}
}
return rc;
}
int pop(char pType, bool pDelay, int pLine) {
int rc = 0;
if (idx && (iSE[idx].type == pType)) {
if (iSE[idx].fold) {
fS.pop(iSE[idx].type, iSE[idx].fold, pDelay, pLine);
}
rc = idx--;
}
return rc;
}
char getType (int back = 0) {
char rc = ' ';
if (back > -idx) {
rc = iSE[idx + back].type;
}
return rc;
}
bool getIsState (int back = 0) {
bool rc = false;
if (back > -idx) {
rc = iSE[idx + back].isState;
}
return rc;
}
int getLine (int back = 0) {
int rc = 0;
if (back > -idx) {
rc = iSE[idx + back].line;
}
return rc;
}
int getFold (bool pPurge) {
return fS.getFold(pPurge);
}
int getFoldWhite () {
return fS.getFoldWhite();
}
bool getFoldHead () {
return fS.getFoldHead();
}
int updateType (char pnew, char pold) {
int rc = 0;
if (idx && (iSE[idx].type == pold)) {
iSE[idx].type = pnew;
rc = idx;
}
return rc;
}
protected:
FoldStack fS;
int idx;
int line;
int size;
InstStackE *iSE;
//
// Foldable items are included in first keyword list
// {cmd} is any item in second keyword list except
// (for, if, loop and while)
//
// omitting an item from a list negates program actions
//
// Fold Type Values
// /** ! Doxygen Stream Comment
// /*! ! Doxygen Stream Comment
// /* * Generic Stream Comment
// --{ - Block (--{, --}) Comment
// //{ / Block (//{, //}) Comment
// " Double Quoted String
// ' Single Quoted String
// ` BackQuoted String
// ( ) Parenthesis Block
// { } Curly Brace Block
// [ ] Square Brackets
// case c/C Case Statement
// do d/D Do Statement
// e/E Exists Function (SQLANY)
// for f/F For Statement
// if i/I If Statement
// loop l/L Loop Statement
// switch s/S Switch Statement
// while w/W While Statement
// <? ? XML Header
// <!-- < XML Header
// < t/T XML Tag Start
// </ u/U XML Tag End
// {cmd} ; Other statements
//
// state contains the IsStatement value when the item initiated
// internal to a statement - true
// case, exists and (opt) if
// statements that contain statements - false
// for, (opt) if, loop, switch (tbd) and while
// if with a State = true - ends with an endif
// if with a State = false - ends with an end if;
//
void init (const InstStackE *array, int sz) {
idx = 0;
line = 0;
size = sz;
iSE = new InstStackE[size];
assert( iSE != 0 );
}
};
#ifdef SCI_NAMESPACE
}
#endif
#endif