OT? identifying elements of C++

K

Kaleb Pederson

Does anybody know of a query language or structure that could be used
for identifying "refactorable" elements of C++? As I suppose that's a
fairly ambiguous question, I'll clarify a bit. I'm working on a
refactoring tool and I want users to be able to define which elements
to which a single refactoring should be applied. A fairly weak and
simplistic approach might be (using a sort-of-regexp based notation):

(Member::)*Member

Thus, I could identify:

- a namespace at any level (e.g. MyNamespace, Namespace1::Namespace2)
- a class within a namespace (e.g. MyNamespace::MyClass, SomeClass)
- a member of a class (e.g. AClass::someVar, ANamespace::MyClass::a)

But there's obviously many things it doesn't handle. So, it could be
extended to allow regexp based matching of members:

(Member::|/regexp/::)*(Member|/regexp/)

Now, I could match many classes

- any class containing the name Node within a namespace (e.g.
MyNS::/.*Node/)

Of course, other things complicate matters. What if I want to
identify a type rather than an instance?

Here's a simple untested C++ example of which I might want to make
such a query:

template <typename T> void doSomething(T node) {
T tmp = node->copy();
// do semthing with tmp
}

namespace A {
class FirstNode { FirstNode copy() {/*...*/} };
class SecondNode { SecondNode copy() {/*...*/} };
struct ThirdNode { ThirdNode copy() {/*...*/} };
} // end ns

In the above example, I might know that all classes or structs within
namespace A that end with the word Node contain a copy() member that
really should be called instance(), thus I would want to allow
multiple elements to be queried. For this example, using the above
syntax I might write: `A::/.*Node/`.

I have some EBNF that supports quite a bit more than the above and
could include other details as necessary, but didn't want to post
something too off topic. Does anybody know of any query languages or
structures that might work for this? or even a better place to ask?

Thanks.

--Kaleb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top