00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "comma/ast/DSTDefinition.h"
00010 #include "comma/ast/ExceptionRef.h"
00011 #include "comma/ast/Expr.h"
00012 #include "comma/ast/KeywordSelector.h"
00013 #include "comma/ast/Pragma.h"
00014 #include "comma/ast/RangeAttrib.h"
00015 #include "comma/ast/Stmt.h"
00016
00017 #include <iostream>
00018
00019 using namespace comma;
00020 using llvm::dyn_cast;
00021 using llvm::cast;
00022 using llvm::isa;
00023
00024
00025
00026 bool Stmt::isTerminator() const
00027 {
00028 return isa<ReturnStmt>(this) || isa<RaiseStmt>(this);
00029 }
00030
00031
00032
00033 bool StmtSequence::hasCatchAll() const
00034 {
00035 if (isHandled())
00036 return handlers.back()->isCatchAll();
00037 return false;
00038 }
00039
00040 bool StmtSequence::handles(const ExceptionDecl *exception) const
00041 {
00042 if (!isHandled())
00043 return false;
00044
00045 if (hasCatchAll())
00046 return true;
00047
00048 for (const_handler_iter I = handler_begin(); I != handler_end(); ++I)
00049 if ((*I)->handles(exception))
00050 return true;
00051
00052 return false;
00053 }
00054
00055
00056
00057 HandlerStmt::HandlerStmt(Location loc, ExceptionRef **refs, unsigned numRefs)
00058 : StmtSequence(AST_HandlerStmt, loc),
00059 numChoices(numRefs)
00060 {
00061 choices = new ExceptionRef*[numChoices];
00062 std::memcpy(choices, refs, sizeof(ExceptionRef*)*numRefs);
00063 }
00064
00065 bool HandlerStmt::handles(const ExceptionDecl *exception) const
00066 {
00067 for (const_choice_iterator I = choice_begin(); I != choice_end(); ++I) {
00068 const ExceptionRef *ref = *I;
00069 if (ref->getException() == exception)
00070 return true;
00071 }
00072 return false;
00073 }
00074
00075
00076
00077 ProcedureCallStmt::ProcedureCallStmt(SubroutineRef *ref,
00078 Expr **posArgs, unsigned numPos,
00079 KeywordSelector **keys, unsigned numKeys)
00080 : Stmt(AST_ProcedureCallStmt, ref->getLocation()),
00081 SubroutineCall(ref, posArgs, numPos, keys, numKeys)
00082 {
00083 assert(ref->isResolved() && "Cannot form unresolved procedure calls!");
00084 }
00085
00086
00087
00088 ReturnStmt::~ReturnStmt()
00089 {
00090 if (returnExpr) delete returnExpr;
00091 }
00092
00093
00094
00095 AssignmentStmt::AssignmentStmt(Expr *target, Expr *value)
00096 : Stmt(AST_AssignmentStmt, target->getLocation()),
00097 target(target), value(value) { }
00098
00099
00100
00101
00102 ForStmt::ForStmt(Location loc, LoopDecl *iterationDecl, DSTDefinition *control)
00103 : Stmt(AST_ForStmt, loc),
00104 iterationDecl(iterationDecl),
00105 control(control),
00106 body(loc)
00107 {
00108 assert(control->getTag() != DSTDefinition::Unconstrained_DST &&
00109 "Invalid discrete subtype definition for loop control!");
00110 assert(control->getType() == iterationDecl->getType() &&
00111 "Inconsistent types!");
00112 }
00113
00114
00115
00116 PragmaStmt::PragmaStmt(Pragma *pragma)
00117 : Stmt(AST_PragmaStmt, pragma->getLocation()), pragma(pragma)
00118 { }
00119
00120
00121
00122
00123 const ExceptionDecl *RaiseStmt::getExceptionDecl() const
00124 {
00125 return ref->getException();
00126 }
00127
00128 ExceptionDecl *RaiseStmt::getExceptionDecl()
00129 {
00130 return ref->getException();
00131 }