SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

NRefactory Parsing preprocessor as methods comment

Last post 09-01-2014 1:11 PM by tsadigov. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 08-30-2014 3:10 AM

    NRefactory Parsing preprocessor as methods comment

    When parsing PreProcessorDirective node is being put under wrong node

    Here what I use

      ///<summary>

    ///...

      ///</summary>

      #if !SQLITE_OMIT_ATTACH

      ///<summary>
      /// ...
      ///</summary>
      static void attachFunc(sqlite3_context context,int NotUsed,sqlite3_value[ argv) {
      }

    #endif

    When parsing this code MethodDeclaration for attachFunc will have comments as its child plus #if line. And if I move this node somewhere I get inconsistent preprocessor without opening

  • 08-30-2014 3:45 AM In reply to

    Re: NRefactory Parsing preprocessor as methods comment

    It appears that this is the method where confusion happens
    In CShrpParser.cs

    void InsertComments(CompilerCompilationUnit top, ConversionVisitor conversionVisitor)

    also

     

    static void InsertComment(ref AstNode insertionPoint, AstNode newNode, Role role, bool isDocumentationComment, AstNode rootNode)

     

     

     

     

    {

     

     

     

    ......

    // As a special case, XmlDoc gets inserted at the beginning of the entity declaration

     

     

     

    if (isDocumentationComment && insertionPoint is EntityDeclaration && insertionPoint.FirstChild != null) {

    insertionPoint = insertionPoint.FirstChild;

     

     

     

     

    }

     

     

     

    This causes cursor to point to move to definitions modifier, which will be used in the next line

    insertionPoint.Parent.InsertChildBeforeUnsafe(insertionPoint, newNode, role);

     

  • 08-30-2014 1:17 PM In reply to

    Re: NRefactory Parsing preprocessor as methods comment

    If you have a preprocessor directive in the middle of a documentation comment, it is expected behavior that the PreprocessorDirective node will be a child of the method declaration (same as the documentation comment).

    In general, you cannot rely on matching preprocessor directives (#if/#endif, or #region/#endregion) being siblings in the AST.

  • 08-31-2014 12:54 PM In reply to

    Re: NRefactory Parsing preprocessor as methods comment

    Dear sir
    thanks for your response

    I am trying to use NRefactory for custom refactorings to hep me understand and transform code written by others.
    I used it for Sqlite and it is originally written in C and preprocessors are widely used there.

    Now when I move MethodDeclaration in AST tree it breaks AST. I am not talking about implementation but logically preprocessor directive outside method should not belong to the method. In case of documentation comments it makes sense. But adding opening Proprocessor node to method declarations subtree and leaving closing node outside doesnt make sense to me. It is right that somebody should not put directives and comments in such way but I cant rely on this I am trying to automate my tasks and compiler is ok with that code.

     

  • 08-31-2014 12:58 PM In reply to

    Re: NRefactory Parsing preprocessor as methods comment

    '#if' can be placed in all kinds of weird places:

    For example:

    void A()
    {
    #if USE_SEPARATE_METHODS
    B();
    }

    void B()
    {
    #endif
    }

    Reliable automatic refactorings are impossible in the presence of #if.

  • 08-31-2014 6:35 PM In reply to

    Re: NRefactory Parsing preprocessor as methods comment

    you are absolutely right

    in the example you have provided it is not obvious what coder intended it can be confusing

    but in the example below it is not that confusing and can be handled by the parser because the opening and closing preprocessors dont mess up with the hierarchy

    /// comment outside

    #if

    ///coment inside

    public void testMethod(){

     

    }

     

    #endif

     

     

  • 08-31-2014 9:53 PM In reply to

    Re: NRefactory Parsing preprocessor as methods comment

    NRefactory works as designed.

    If you want a different design, you'll have to be more specific than 'the parser can handle this'

  • 09-01-2014 1:11 PM In reply to

    Re: NRefactory Parsing preprocessor as methods comment

    Specifically what I want is the parser include only the comment [///coment inside] into the method declaration, not the [#if] preprocessor directive. Because that directive does not belong to method.

     

Page 1 of 1 (8 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.