diff options
| author | nyamatongwe <unknown> | 2011-03-27 11:13:43 +1100 | 
|---|---|---|
| committer | nyamatongwe <unknown> | 2011-03-27 11:13:43 +1100 | 
| commit | 790d04e00e42a613c132444def2faa432534d366 (patch) | |
| tree | 06942d02ef53e080b55858804699f2666358dacf /lexers/LexCPP.cxx | |
| parent | 87991c388af3123089d1d04b3d16ac7b6c0fd014 (diff) | |
| download | scintilla-mirror-790d04e00e42a613c132444def2faa432534d366.tar.gz | |
Fix folding of inactive code.
Diffstat (limited to 'lexers/LexCPP.cxx')
| -rw-r--r-- | lexers/LexCPP.cxx | 30 | 
1 files changed, 16 insertions, 14 deletions
| diff --git a/lexers/LexCPP.cxx b/lexers/LexCPP.cxx index f573befaa..0d5f2afb7 100644 --- a/lexers/LexCPP.cxx +++ b/lexers/LexCPP.cxx @@ -319,6 +319,7 @@ class LexerCPP : public ILexer {  	OptionsCPP options;  	OptionSetCPP osCPP;  	SparseState<std::string> rawStringTerminators; +	enum { activeFlag = 0x40 };  public:  	LexerCPP(bool caseSensitive_) :  		caseSensitive(caseSensitive_), @@ -363,7 +364,9 @@ public:  	static ILexer *LexerFactoryCPPInsensitive() {  		return new LexerCPP(false);  	} - +	static int MaskActive(int style) { +		return style & ~activeFlag; +	}  	void EvaluateTokens(std::vector<std::string> &tokens);  	bool EvaluateExpression(const std::string &expr, const std::map<std::string, std::string> &preprocessorDefinitions);  }; @@ -503,11 +506,10 @@ void SCI_METHOD LexerCPP::Lex(unsigned int startPos, int length, int initStyle,  		preprocessorDefinitions[itDef->key] = itDef->value;  	} -	const int maskActivity = 0x3F;  	std::string rawStringTerminator = rawStringTerminators.ValueAt(lineCurrent-1);  	SparseState<std::string> rawSTNew(lineCurrent); -	int activitySet = preproc.IsInactive() ? 0x40 : 0; +	int activitySet = preproc.IsInactive() ? activeFlag : 0;  	for (; sc.More(); sc.Forward()) { @@ -523,7 +525,7 @@ void SCI_METHOD LexerCPP::Lex(unsigned int startPos, int length, int initStyle,  			lastWordWasUUID = false;  			isIncludePreprocessor = false;  			if (preproc.IsInactive()) { -				activitySet = 0x40; +				activitySet = activeFlag;  				sc.SetState(sc.state | activitySet);  			}  			if (activitySet) { @@ -558,7 +560,7 @@ void SCI_METHOD LexerCPP::Lex(unsigned int startPos, int length, int initStyle,  		const bool atLineEndBeforeSwitch = sc.atLineEnd;  		// Determine if the current state should terminate. -		switch (sc.state & maskActivity) { +		switch (MaskActive(sc.state)) {  			case SCE_C_OPERATOR:  				sc.SetState(SCE_C_DEFAULT|activitySet);  				break; @@ -754,7 +756,7 @@ void SCI_METHOD LexerCPP::Lex(unsigned int startPos, int length, int initStyle,  		}  		// Determine if a new state should be entered. -		if ((sc.state & maskActivity) == SCE_C_DEFAULT) { +		if (MaskActive(sc.state) == SCE_C_DEFAULT) {  			if (sc.Match('@', '\"')) {  				sc.SetState(SCE_C_VERBATIM|activitySet);  				sc.Forward(); @@ -839,12 +841,12 @@ void SCI_METHOD LexerCPP::Lex(unsigned int startPos, int length, int initStyle,  						} else if (sc.Match("else")) {  							if (!preproc.CurrentIfTaken()) {  								preproc.InvertCurrentLevel(); -								activitySet = preproc.IsInactive() ? 0x40 : 0; +								activitySet = preproc.IsInactive() ? activeFlag : 0;  								if (!activitySet)  									sc.ChangeState(SCE_C_PREPROCESSOR|activitySet);  							} else if (!preproc.IsInactive()) {  								preproc.InvertCurrentLevel(); -								activitySet = preproc.IsInactive() ? 0x40 : 0; +								activitySet = preproc.IsInactive() ? activeFlag : 0;  								if (!activitySet)  									sc.ChangeState(SCE_C_PREPROCESSOR|activitySet);  							} @@ -856,19 +858,19 @@ void SCI_METHOD LexerCPP::Lex(unsigned int startPos, int length, int initStyle,  								bool ifGood = EvaluateExpression(restOfLine, preprocessorDefinitions);  								if (ifGood) {  									preproc.InvertCurrentLevel(); -									activitySet = preproc.IsInactive() ? 0x40 : 0; +									activitySet = preproc.IsInactive() ? activeFlag : 0;  									if (!activitySet)  										sc.ChangeState(SCE_C_PREPROCESSOR|activitySet);  								}  							} else if (!preproc.IsInactive()) {  								preproc.InvertCurrentLevel(); -								activitySet = preproc.IsInactive() ? 0x40 : 0; +								activitySet = preproc.IsInactive() ? activeFlag : 0;  								if (!activitySet)  									sc.ChangeState(SCE_C_PREPROCESSOR|activitySet);  							}  						} else if (sc.Match("endif")) {  							preproc.EndSection(); -							activitySet = preproc.IsInactive() ? 0x40 : 0; +							activitySet = preproc.IsInactive() ? activeFlag : 0;  							sc.ChangeState(SCE_C_PREPROCESSOR|activitySet);  						} else if (sc.Match("define")) {  							if (options.updatePreprocessor && !preproc.IsInactive()) { @@ -928,15 +930,15 @@ void SCI_METHOD LexerCPP::Fold(unsigned int startPos, int length, int initStyle,  	int levelMinCurrent = levelCurrent;  	int levelNext = levelCurrent;  	char chNext = styler[startPos]; -	int styleNext = styler.StyleAt(startPos); -	int style = initStyle; +	int styleNext = MaskActive(styler.StyleAt(startPos)); +	int style = MaskActive(initStyle);  	const bool userDefinedFoldMarkers = !options.foldExplicitStart.empty() && !options.foldExplicitEnd.empty();  	for (unsigned int i = startPos; i < endPos; i++) {  		char ch = chNext;  		chNext = styler.SafeGetCharAt(i + 1);  		int stylePrev = style;  		style = styleNext; -		styleNext = styler.StyleAt(i + 1); +		styleNext = MaskActive(styler.StyleAt(i + 1));  		bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');  		if (options.foldComment && options.foldCommentMultiline && IsStreamCommentStyle(style)) {  			if (!IsStreamCommentStyle(stylePrev) && (stylePrev != SCE_C_COMMENTLINEDOC)) { | 
