~ubuntu-branches/ubuntu/lucid/monodevelop/lucid

« back to all changes in this revision

Viewing changes to src/addins/CSharpBinding/MonoDevelop.CSharp.Highlighting/CSharpSyntaxMode.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-02-02 11:39:59 UTC
  • mfrom: (1.2.6 upstream) (1.3.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100202113959-s4exdz7er7igylz2
Tags: 2.2.1+dfsg-1
* New upstream release
* debian/control:
  + Standards version 3.8.4 (no changes needed)
* debian/patches/remove_support_for_non_debian_functionality.patch,
  debian/patches/remove_support_for_soft_debugger.patch,
  debian/patches/remove_support_for_moonlight.patch,
  debian/rules:
  + Split patch into two pieces, to make it easier to enable either
    SDB or Moonlight support with a rebuild
* debian/monodevelop-moonlight.install,
  debian/monodevelop-debugger-sdb.install,
  debian/control:
  + Create packaging data for the Soft Debugger addin and Moonlight addin -
    and comment them out of debian/control as we can't provide them on
    Debian for now

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
using MonoDevelop.Projects;
36
36
using MonoDevelop.CSharp.Project;
37
37
using MonoDevelop.Core;
 
38
using MonoDevelop.Projects.Dom.Parser;
 
39
using MonoDevelop.Projects.Dom;
38
40
 
39
41
namespace MonoDevelop.CSharp.Highlighting
40
42
{
177
179
                        class ConditinalExpressionEvaluator : ICSharpCode.NRefactory.Visitors.AbstractAstVisitor
178
180
                        {
179
181
                                HashSet<string> symbols = new HashSet<string> ();
180
 
                                public ConditinalExpressionEvaluator ()
 
182
                                
 
183
                                public ConditinalExpressionEvaluator (Document doc)
181
184
                                {
182
185
                                        var project = MonoDevelop.Ide.Gui.IdeApp.ProjectOperations.CurrentSelectedProject;
183
186
                                        if (project != null) {
184
 
                                                CSharpCompilerParameters cparams = ((DotNetProjectConfiguration)project.GetConfiguration (project.ParentSolution.DefaultConfigurationSelector)).CompilationParameters as CSharpCompilerParameters;
185
 
                                                if (cparams != null) {
186
 
                                                        string[] syms = cparams.DefineSymbols.Split (';', ',');
187
 
                                                        foreach (string s in syms) {
188
 
                                                                string ss = s.Trim ();
189
 
                                                                if (ss.Length > 0 && !symbols.Contains (ss))
190
 
                                                                        symbols.Add (ss);
 
187
                                                DotNetProjectConfiguration configuration = project.GetConfiguration (project.ParentSolution.DefaultConfigurationSelector) as DotNetProjectConfiguration;
 
188
                                                if (configuration != null) {
 
189
                                                        CSharpCompilerParameters cparams = configuration.CompilationParameters as CSharpCompilerParameters;
 
190
                                                        if (cparams != null) {
 
191
                                                                string[] syms = cparams.DefineSymbols.Split (';', ',');
 
192
                                                                foreach (string s in syms) {
 
193
                                                                        string ss = s.Trim ();
 
194
                                                                        if (ss.Length > 0 && !symbols.Contains (ss))
 
195
                                                                                symbols.Add (ss);
 
196
                                                                }
191
197
                                                        }
192
198
                                                }
193
199
                                        }
 
200
                                        
 
201
                                        ProjectDom dom = ProjectDomService.GetProjectDom (project);
 
202
                                        ParsedDocument parsedDocument = ProjectDomService.GetParsedDocument (dom, doc.FileName);
 
203
                                        if (parsedDocument == null)
 
204
                                                parsedDocument = ProjectDomService.ParseFile (dom, doc.FileName ?? "a.cs", delegate { return doc.Text; });
 
205
                                        if (parsedDocument != null) {
 
206
                                                foreach (PreProcessorDefine define in parsedDocument.Defines) {
 
207
                                                        symbols.Add (define.Define);
 
208
                                                }
 
209
                                        }
194
210
                                }
195
211
                                
196
212
                                public override object VisitIdentifierExpression (ICSharpCode.NRefactory.Ast.IdentifierExpression identifierExpression, object data)
238
254
                                        base.ScanSpan (ref i);
239
255
                                        return;
240
256
                                }
241
 
                                if (i + 5 < doc.Length && doc.GetTextAt (i, 5) == "#else" && spanStack.Any (span => span is IfBlockSpan)) {
 
257
                                if (i + 5 < doc.Length && doc.GetTextAt (i, 5) == "#else") {
 
258
                                        LineSegment line = doc.GetLineByOffset (i);
 
259
                                        
242
260
                                        bool previousResult = false;
 
261
                                        
243
262
                                        foreach (Span span in spanStack.ToArray ().Reverse ()) {
244
263
                                                if (span is IfBlockSpan) {
245
264
                                                        previousResult = ((IfBlockSpan)span).IsValid;
249
268
                                                }
250
269
                                        }
251
270
                                        
252
 
                                        LineSegment line = doc.GetLineByOffset (i);
 
271
                                        
253
272
                                        int length = line.Offset + line.EditableLength - i;
254
273
                                        while (spanStack.Count > 0 && !(CurSpan is IfBlockSpan)) {
255
274
                                                spanStack.Pop ();
256
275
                                        }
257
276
//                                      IfBlockSpan ifBlock = (IfBlockSpan)CurSpan;
258
 
                                        
259
277
                                        ElseBlockSpan elseBlockSpan = new ElseBlockSpan (!previousResult);
260
278
                                        OnFoundSpanBegin (elseBlockSpan, i, 0);
261
279
                                        
269
287
                                        i += length - 1;
270
288
                                        return;
271
289
                                }
 
290
                                
272
291
                                if (CurRule.Name == "text.preprocessor" && i >= 3 && doc.GetTextAt (i - 3, 3) == "#if") {
273
292
                                        LineSegment line = doc.GetLineByOffset (i);
274
293
                                        int length = line.Offset + line.EditableLength - i;
277
296
                                        ICSharpCode.NRefactory.Ast.Expression expr = lexer.PPExpression ();
278
297
                                        bool result = false;
279
298
                                        if (expr != null && !expr.IsNull) {
280
 
                                                object o = expr.AcceptVisitor (new ConditinalExpressionEvaluator (), null);
 
299
                                                object o = expr.AcceptVisitor (new ConditinalExpressionEvaluator (doc), null);
281
300
                                                if (o is bool)
282
301
                                                        result = (bool)o;
283
302
                                        }
296
315
                                        ICSharpCode.NRefactory.Parser.CSharp.Lexer lexer = new ICSharpCode.NRefactory.Parser.CSharp.Lexer (new System.IO.StringReader (parameter));
297
316
                                        ICSharpCode.NRefactory.Ast.Expression expr = lexer.PPExpression ();
298
317
                                
299
 
                                        bool result = !expr.IsNull ? (bool)expr.AcceptVisitor (new ConditinalExpressionEvaluator (), null) : false;
 
318
                                        bool result = !expr.IsNull ? (bool)expr.AcceptVisitor (new ConditinalExpressionEvaluator (doc), null) : false;
300
319
                                        
301
320
                                        if (result) {
302
321
                                                bool previousResult = false;