Otawa  0.10
AST.h
Go to the documentation of this file.
1 /*
2  * AST class interface
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2003, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef OTAWA_AST_AST_H
22 #define OTAWA_AST_AST_H
23 
24 #include <elm/util/AutoPtr.h>
25 #include <otawa/instruction.h>
26 #include <otawa/program.h>
27 
28 namespace otawa { namespace ast {
29 
30 // Defined AST
31 class BlockAST;
32 class CallAST;
33 class SeqAST;
34 class IfAST;
35 class WhileAST;
36 class DoWhileAST;
37 class ForAST;
38 
39 // AST Kind
40 typedef enum ast_kind_t {
50 } ast_kind_t;
51 
52 // AST Class
53 class AST: public elm::Lock, public PropList {
54  friend class FunAST;
55 protected:
56  virtual ~AST(void) { };
57 public:
58  static AST& NOP;
59  static AST& UNDEF;
60  virtual ast_kind_t kind(void) const = 0;
61  virtual Inst *first(void) = 0;
62  virtual void release(void);
63 
64  virtual bool isNOP(void) { return false; };
65  virtual bool isUndef(void) { return false; };
66  virtual BlockAST *toBlock(void) { return 0; };
67  virtual CallAST *toCall(void) { return 0; };
68  virtual SeqAST *toSeq(void) { return 0; };
69  virtual IfAST *toIf(void) { return 0; };
70  virtual WhileAST *toWhile(void) { return 0; };
71  virtual DoWhileAST *toDoWhile(void) { return 0; };
72  virtual ForAST *toFor(void) { return 0; };
73  virtual int countInstructions(void) const = 0;
74 };
75 
76 } } // otawa::ast
77 
78 #endif // OTAWA_AST_AST_H
Definition: AST.h:43
Definition: AST.h:41
This class represents functions in the AST representation.
Definition: FunAST.h:32
Representation of C language FOR loop.
Definition: ForAST.h:29
Representation of an iteration with test at start of the loop.
Definition: WhileAST.h:29
static AST & UNDEF
Unique instance of the Undef AST.
Definition: AST.h:59
Definition: AST.h:44
virtual ast_kind_t kind(void) const =0
Get the kind of the AST.
Definition: AST.h:47
This class is a specialized block AST ended by a function call.
Definition: CallAST.h:30
virtual IfAST * toIf(void)
Get the selection AST if this AST is a selection, null else.
Definition: AST.h:69
virtual BlockAST * toBlock(void)
Get the block AST if this AST is a block, null else.
Definition: AST.h:66
virtual ~AST(void)
Definition: AST.h:56
Definition: AST.h:48
Definition: AST.h:46
static AST & NOP
Unique instance of the NOP AST.
Definition: AST.h:56
virtual int countInstructions(void) const =0
Count the number of instructions in the ast block.
Definition: AST.cpp:174
Definition: AST.h:42
virtual void release(void)
Deletion of AST can only be performed using this method.
Definition: AST.cpp:92
Definition: AST.h:49
virtual Inst * first(void)=0
virtual SeqAST * toSeq(void)
Get the sequence AST if this AST is a sequence, null else.
Definition: AST.h:68
virtual ForAST * toFor(void)
Get the repetition AST if this AST is a repetition, null else.
Definition: AST.h:72
virtual bool isNOP(void)
Test if the AST is the NOP AST.
Definition: AST.h:64
virtual CallAST * toCall(void)
Get the call AST if this AST is a call, null else.
Definition: AST.h:67
Definition: AST.h:45
virtual WhileAST * toWhile(void)
Get the repetition AST if this AST is a repeatition, null else.
Definition: AST.h:70
AST for representing selections.
Definition: IfAST.h:29
This class represents the leafs of the AST.
Definition: BlockAST.h:30
This is the base class for the representation of programs as Abstract Syntax Trees.
Definition: AST.h:53
virtual DoWhileAST * toDoWhile(void)
Get the repetition AST if this AST is a repetition, null else.
Definition: AST.h:71
This class represents assembly instruction of a piece of code.
Definition: Inst.h:62
virtual bool isUndef(void)
Test if the AST is the undefined AST.
Definition: AST.h:65
This a list of properties.
Definition: PropList.h:63
This AST represents sequences.
Definition: SeqAST.h:29
ast_kind_t
Definition: AST.h:40
Representation of C do{ ...
Definition: DoWhileAST.h:29