Statements that end with ;

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Statements that end with ;

madil90
Hi,
  I need to identify statements that end with ";". I mean, how does clang represent a statement that is executed independently e.g.

int a;    // what type of statement is this?

a = a + 2;   // or this?

Regards,
Adil
Reply | Threaded
Open this post in threaded view
|

Re: Statements that end with ;

Yang Chen
madil90 wrote:
> Hi,
>   I need to identify statements that end with ";". I mean, how does clang
> represent a statement that is executed independently e.g.
>  

You can check all statement classes here:

http://clang.llvm.org/doxygen/classclang_1_1Stmt.html

> int a;    // what type of statement is this?
>  

I assume you define ``a'' as a local variable, then ``int a;'' is a
DeclStmt.

> a = a + 2;   // or this?
>  

It's a BinaryOperator -

http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html

- Yang

> Regards,
> Adil
>
>
>
> --
> View this message in context: http://clang-developers.42468.n3.nabble.com/Statements-that-end-with-tp4028311.html
> Sent from the Clang Developers mailing list archive at Nabble.com.
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>  

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Statements that end with ;

madil90
Hi,
   I think I didn't state my question correctly. I meant that is there some way to visit statements that end with ";" and are executed in one execution cycle. I just want to identify whether a statement started after a ";" and ended with a ";". e.g.

int a;

a = a + 2;

   I only want to visit these two lines. How can I tell these two statements apart from things like DeclRefExpr which need to have a parent statement that includes them (DeclRefExpr is not a statement type that can be executed)

Regards,
Adil


On Sat, Nov 17, 2012 at 1:59 AM, Yang Chen <[hidden email]> wrote:
madil90 wrote:
Hi,
  I need to identify statements that end with ";". I mean, how does clang
represent a statement that is executed independently e.g.
 

You can check all statement classes here:

http://clang.llvm.org/doxygen/classclang_1_1Stmt.html

int a;    // what type of statement is this?
 

I assume you define ``a'' as a local variable, then ``int a;'' is a DeclStmt.

a = a + 2;   // or this?
 

It's a BinaryOperator -

http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html

- Yang

Regards,
Adil



--
View this message in context: http://clang-developers.42468.n3.nabble.com/Statements-that-end-with-tp4028311.html
Sent from the Clang Developers mailing list archive at Nabble.com.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
 




--
Mohammad Adil
LUMS SSE


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Statements that end with ;

madil90
Hi,
   I need to rewrite at the end of line. In order for the edited code to compile, I must ensure that I write after a ";" character. I just need to find that character. I have a ParentMap that has all the statements. How can I figure out which type of statements have a ";" at the end and which don't? (I just need to differentiate these two types)

Regards,
Adil


On Sat, Nov 17, 2012 at 2:09 AM, Mohammad Adil <[hidden email]> wrote:
Hi,
   I think I didn't state my question correctly. I meant that is there some way to visit statements that end with ";" and are executed in one execution cycle. I just want to identify whether a statement started after a ";" and ended with a ";". e.g.

int a;

a = a + 2;

   I only want to visit these two lines. How can I tell these two statements apart from things like DeclRefExpr which need to have a parent statement that includes them (DeclRefExpr is not a statement type that can be executed)

Regards,
Adil


On Sat, Nov 17, 2012 at 1:59 AM, Yang Chen <[hidden email]> wrote:
madil90 wrote:
Hi,
  I need to identify statements that end with ";". I mean, how does clang
represent a statement that is executed independently e.g.
 

You can check all statement classes here:

http://clang.llvm.org/doxygen/classclang_1_1Stmt.html

int a;    // what type of statement is this?
 

I assume you define ``a'' as a local variable, then ``int a;'' is a DeclStmt.

a = a + 2;   // or this?
 

It's a BinaryOperator -

http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html

- Yang

Regards,
Adil



--
View this message in context: http://clang-developers.42468.n3.nabble.com/Statements-that-end-with-tp4028311.html
Sent from the Clang Developers mailing list archive at Nabble.com.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
 




--
Mohammad Adil
LUMS SSE




--
Mohammad Adil
LUMS SSE


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Statements that end with ;

Yang Chen
On 11/16/2012 6:09 PM, Mohammad Adil wrote:
> Hi,
>     I need to rewrite at the end of line. In order for the edited code
> to compile, I must ensure that I write after a ";" character. I just
> need to find that character. I have a ParentMap that has all the
> statements. How can I figure out which type of statements have a ";" at
> the end and which don't? (I just need to differentiate these two types)

I am not sure your purpose of using ParentMap, but for discriminating
between two kinds of statements you mentioned, one approach would be to
write an AST Visitor derived from RecursiveASTVisitor:

http://clang.llvm.org/doxygen/classclang_1_1RecursiveASTVisitor.html

And then you implement a couple of VisitXXXStmt methods -

bool YourVisitor::VisitCompoundStmt(CompoundStmt *CS)
{
   // here you iterate the body of CS;

   // for each semi-colon-ended statement with respect to C's syntax
rules, you can get the end location of it using getLocEnd method;

   // from the end location, you can find the location of ';' (for the
debugging purpose, you might also want to dump and check the string
starting from the end location using
SourceManager::getCharacterData(Loc) method);

   // Last, get a Rewriter instance and do rewriting
}

bool YourVisitor::VisitIfStmt(IfStmt *IS)
{
   // here you check the "Then" Stmt and "Else" Stmt of IS;

   // you only need to handle the case where ThenStmt and ElseStmt are
semi-colon-ended statements; (Note that you don't want to iterate these
two statements if they are CompoundStmt[s], which will be visited from
VisitCompoundStmt)
}

bool YourVisitor::VisitWhileStmt(WhileStmt *WS)
{
   // similar to VisitIfStmt, but you only need to handle the "body"
Stmt of WS;
}

...


Note that there could be other ways, e.g., using ASTMatcher, which I
never tried, but it should be easy to use.

In any case, you will still need to follow C's syntax rules while
analyzing C code, assuming you are dealing with C programs.

- Yang

>
> Regards,
> Adil
>
>
> On Sat, Nov 17, 2012 at 2:09 AM, Mohammad Adil <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Hi,
>         I think I didn't state my question correctly. I meant that is
>     there some way to visit statements that end with ";" and are
>     executed in one execution cycle. I just want to identify whether a
>     statement started after a ";" and ended with a ";". e.g.
>
>     int a;
>
>     a = a + 2;
>
>         I only want to visit these two lines. How can I tell these two
>     statements apart from things like DeclRefExpr which need to have a
>     parent statement that includes them (DeclRefExpr is not a statement
>     type that can be executed)
>
>     Regards,
>     Adil
>
>
>     On Sat, Nov 17, 2012 at 1:59 AM, Yang Chen <[hidden email]
>     <mailto:[hidden email]>> wrote:
>
>         madil90 wrote:
>
>             Hi,
>                I need to identify statements that end with ";". I mean,
>             how does clang
>             represent a statement that is executed independently e.g.
>
>
>         You can check all statement classes here:
>
>         http://clang.llvm.org/doxygen/__classclang_1_1Stmt.html
>         <http://clang.llvm.org/doxygen/classclang_1_1Stmt.html>
>
>             int a;    // what type of statement is this?
>
>
>         I assume you define ``a'' as a local variable, then ``int a;''
>         is a DeclStmt.
>
>             a = a + 2;   // or this?
>
>
>         It's a BinaryOperator -
>
>         http://clang.llvm.org/doxygen/__classclang_1_1BinaryOperator.__html
>         <http://clang.llvm.org/doxygen/classclang_1_1BinaryOperator.html>
>
>         - Yang
>
>             Regards,
>             Adil
>
>
>
>             --
>             View this message in context:
>             http://clang-developers.42468.__n3.nabble.com/Statements-that-__end-with-tp4028311.html
>             <http://clang-developers.42468.n3.nabble.com/Statements-that-end-with-tp4028311.html>
>             Sent from the Clang Developers mailing list archive at
>             Nabble.com.
>             _________________________________________________
>             cfe-dev mailing list
>             [hidden email] <mailto:[hidden email]>
>             http://lists.cs.uiuc.edu/__mailman/listinfo/cfe-dev
>             <http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev>
>
>
>
>
>
>     --
>     Mohammad Adil
>     LUMS SSE
>
>
>
>
> --
> Mohammad Adil
> LUMS SSE
>

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev