Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Incorrect parse of type declaration with template parameters #70

Description

@creachadair

Originally reported by Olivier Mesnard in https://forum.sourced.tech/t/parsing-cpp-code-with-parameterized-types/246.

The CDT C++ parser may be incorrectly treating the template instantiation brackets as operators.

Repro (courtesy of Olivier): Given the sample code

#include <string>
#include <deque>
#include <iostream>

class ParameterizedType {
    public:
        std::deque<std::string> sortPerm(std::string permissions[]);
};

/**
 *  declaration of Parameterized types
 *  @return std::deque<std::string>
 */
    std::deque<std::string> ParameterizedType::sortPerm(std::string permissions[]) {
        // std::string result(0);               // OK, node is cpp:CPPASTDeclarationStatement
        std::deque<std::string>result(0); // NOK, node is cpp:CPPASTBinaryExpression
        return  result;
    }

the following client script demonstrates the bug:

import bblfsh

def main():
    client = bblfsh.BblfshClient("0.0.0.0:9432")
    ctx = client.parse('ParameterizedType.cpp')
    for unode in ctx.filter("//uast:Function"):
        func_node = unode.get()
        assert func_node['@type'] == 'uast:Function'

        block_node = func_node['Body']
        assert block_node['@type'] == 'uast:Block'

        cpp_expression_statement_node = block_node['Statements'][0]
        assert cpp_expression_statement_node['@type'] == 'cpp:CPPASTExpressionStatement'

        cpp_binary_expression_node = cpp_expression_statement_node['Prop_Expression']
        print('type=',cpp_binary_expression_node['@type'])
        assert cpp_binary_expression_node['@type'] == 'cpp:CPPASTDeclarationStatement'

        break
        
if __name__ == '__main__':
   main()

I suspect CDT (or at least the version of it we're using in the driver) may not be up-to-date with the lexical changes from C++11 et seq.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions