Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementations of same structure not grouped in Rust parser #728

Open
peter-scholtens opened this issue Nov 1, 2015 · 1 comment
Open

Comments

@peter-scholtens
Copy link
Contributor

Hello,

While trying operator overloading in Rust, I see some unexepected behaviour of Geany. For a structure called ComplexNumber, the implementation of Add and Mul require separate implementation blocks. I expected that Add and Mul would be listed together with print and magnitude. If I try operator overloading in a similar way in C++, the member functions get nicely grouped below the name of the structure, even if they are defined in separate blocks. See the picture and the attached Rust example.

implementationsrust

use std::ops::{Add,Mul};

#[derive(Debug,Copy,Clone)]
pub struct ComplexNumber {
    r : f64,
    j : f64
}

impl Add for ComplexNumber{
    type Output = ComplexNumber;

    fn add(self, rhs: ComplexNumber) -> ComplexNumber {
        ComplexNumber {r: self.r+rhs.r, j: self.j+rhs.j}
    }

}

impl Mul for ComplexNumber{
    type Output = ComplexNumber;

    fn mul(self, rhs: ComplexNumber) -> ComplexNumber {
        ComplexNumber {r: self.r*rhs.r-self.j*rhs.j, j: self.r*rhs.j+self.j*rhs.r}
    }

}

impl ComplexNumber {
    fn print(& self) {
        print!("{}+{}i ",self.r,self.j);
    }
    fn magnitude(& self) -> f64 {
        (self.r.powi(2)+self.j.powi(2)).sqrt()
    }
}


fn main()
{
    let a = ComplexNumber {r: 1.0, j: 0.0};
    let b = ComplexNumber {r: 0.0, j: 1.0};
    let c = a + b;
    let d = a * b;
    let e = c + d;
    c.print();
    d.print();
    e.print();
    print!("{} ", e.magnitude());
}
peter-scholtens added a commit to peter-scholtens/geany that referenced this issue Aug 13, 2018
I'm trying to solve geany#728, but before that I needed to understand the C-parser. Unfortunately the debugging option failed. I tried the following:
CFLAGS='-DDEBUG_C' ./autogen.sh
And therefore I needed to modify c.c
Hope this is sufficiently clear to accept the change.
@elextr
Copy link
Member

elextr commented Aug 14, 2018

The parsers are taken from the Uctags project, so the first thing to check is if the latest version of Uctags itself has the problem.

If it does then that project is where to fix it. When the problem is fixed in Uctags then swapping the parser included with Geany for the latest from Uctags is the fix for Geany. Thats not a job for the fainthearted though.

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

No branches or pull requests

2 participants