Retrieve referenced LabelSymbol of GotoStatementSyntax

Answered Retrieve referenced LabelSymbol of GotoStatementSyntax

  • Monday, August 20, 2012 2:51 PM
     
      Has Code

    Hi,

    in the example below I want to infer that the goto statement <goto case 1;> (of type GotoStatementSyntax) references the case switch label <case 1:> (of type SwitchLabelSyntax)

    switch(i) {
     case 1:
      // do something
      break;
     case 2:
      goto case 1;
      break;
    }

    I therefor ask for the declared/referenced symbol (of type LabelSymbol). Currently this is what I want do:

    SemanticModel semanticModel;
    SwitchLabelSyntax switchLabelSyntax;
    GotoStatementSyntax gotoStmt;
    
    var switchLabel = semanticModel.GetDeclaredSymbol(switchLabelSyntax)
    var gotoLabel = (LabelSymbol) semanticModel.GetSymbolInfo(gotoStmt).Symbol;

    But this does not work, since I am not allowed to pass gotoStmt to GetSymbolInfo().

    I can retrieve the gotoLabel if gotoStmt references a "normal" label (goto A;) with

    var gotoLabel = (LabelSymbol) semanticModel.GetSymbolInfo(gotoStmt.Expression).Symbol;

    So how would I do that in the first case?




    • Edited by Jochen Huck Monday, August 20, 2012 2:53 PM
    • Edited by Jochen Huck Monday, August 20, 2012 2:53 PM
    • Edited by Jochen Huck Monday, August 20, 2012 2:54 PM
    •  

All Replies

  • Tuesday, August 28, 2012 7:34 PM
    Owner
     
     Answered
    This is something that we would like to support, but hasn't been a high enough priority to do yet.

    -- Kevin Pilch-Bisson kevinpi@microsoft.com

    • Marked As Answer by Jochen Huck Friday, August 31, 2012 9:32 AM
    •  
  • Friday, August 31, 2012 9:36 AM
     
     

    Well thanks for the clarification.

    As a workaround I will write a custom syntax visitor to match <goto case X> expressions with the  corresponding <case X> labels.

    EDIT: If I have time to implement this I will post the workaround here
    • Edited by Jochen Huck Tuesday, September 04, 2012 10:19 PM
    •