00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "AstDumper.h"
00010 #include "comma/ast/Ast.h"
00011 #include "comma/ast/SubroutineRef.h"
00012
00013 #include <algorithm>
00014
00015 using namespace comma;
00016
00017 using llvm::dyn_cast;
00018 using llvm::cast;
00019 using llvm::isa;
00020
00021 const char *Ast::kindStrings[LAST_AstKind] = {
00022 "SignatureDecl",
00023 "DomainDecl",
00024 "VarietyDecl",
00025 "FunctorDecl",
00026 "AddDecl",
00027
00028 "AccessDecl",
00029 "CarrierDecl",
00030 "EnumerationDecl",
00031 "IncompleteTypeDecl",
00032 "IntegerDecl",
00033 "ArrayDecl",
00034 "RecordDecl",
00035 "AbstractDomainDecl",
00036 "DomainInstanceDecl",
00037 "PercentDecl",
00038
00039 "SigInstanceDecl",
00040
00041 "LoopDecl",
00042 "ObjectDecl",
00043 "ParamValueDecl",
00044 "RenamedObjectDecl",
00045
00046 "ProcedureDecl",
00047 "FunctionDecl",
00048 "EnumLiteral",
00049 "PosAD",
00050 "ValAD",
00051 "ImportDecl",
00052 "ExceptionDecl",
00053 "ComponentDecl",
00054
00055 "UniversalType",
00056 "FunctionType",
00057 "ProcedureType",
00058
00059 "AccessType",
00060 "ArrayType",
00061 "DomainType",
00062 "EnumerationType",
00063 "IncompleteType",
00064 "IntegerType",
00065 "RecordType",
00066
00067 "AllocatorExpr",
00068 "ConversionExpr",
00069 "DiamondExpr",
00070 "DeclRefExpr",
00071 "DereferenceExpr",
00072 "FunctionCallExpr",
00073 "IndexedArrayExpr",
00074 "InjExpr",
00075 "IntegerLiteral",
00076 "NullExpr",
00077 "AggregateExpr",
00078 "PrjExpr",
00079 "QualifiedExpr",
00080 "SelectedExpr",
00081 "StringLiteral",
00082
00083 "FirstAE",
00084 "FirstArrayAE",
00085 "LastArrayAE",
00086 "LastAE",
00087
00088 "AssignmentStmt",
00089 "BlockStmt",
00090 "ForStmt",
00091 "HandlerStmt",
00092 "IfStmt",
00093 "LoopStmt",
00094 "NullStmt",
00095 "ProcedureCallStmt",
00096 "RaiseStmt",
00097 "ReturnStmt",
00098 "StmtSequence",
00099 "WhileStmt",
00100 "PragmaStmt",
00101
00102 "KeywordSelector",
00103 "DSTDefinition",
00104 "Range",
00105 "ArrayRangeAttrib",
00106 "ScalarRangeAttrib",
00107 "SubroutineRef",
00108 "TypeRef",
00109 "ExceptionRef",
00110 "Identifier",
00111 "ComponentKey"
00112 };
00113
00114 void Ast::dump()
00115 {
00116 AstDumper dumper(llvm::errs());
00117 dumper.dump(this);
00118 llvm::errs().flush();
00119 }
00120
00121
00122
00123
00124
00125
00126
00127
00128 void SubroutineRef::verify()
00129 {
00130 assert(!decls.empty() && "Empty SubroutineRef!");
00131 SubroutineDecl *elem = decls[0];
00132 IdentifierInfo *name = elem->getIdInfo();
00133 bool isaFunction = isa<FunctionDecl>(elem);
00134 unsigned numDecls = numDeclarations();
00135
00136 for (unsigned i = 1; i < numDecls; ++i) {
00137 SubroutineDecl *cursor = decls[i];
00138 verify(cursor, name, isaFunction);
00139 }
00140 }
00141
00142 void SubroutineRef::verify(SubroutineDecl *decl,
00143 IdentifierInfo *name, bool isaFunction)
00144 {
00145 assert(decl->getIdInfo() == name &&
00146 "All declarations must have the same identifier!");
00147 if (isaFunction)
00148 assert(isa<FunctionDecl>(decl) && "Declaration type mismatch!");
00149 else
00150 assert(isa<ProcedureDecl>(decl) && "Declaration type mismatch!");
00151 }
00152
00153 void SubroutineRef::addDeclaration(SubroutineDecl *srDecl)
00154 {
00155 if (decls.empty())
00156 decls.push_back(srDecl);
00157 else {
00158 IdentifierInfo *name = getIdInfo();
00159 bool isaFunction = referencesFunctions();
00160 verify(srDecl, name, isaFunction);
00161 decls.push_back(srDecl);
00162 }
00163 }
00164
00165 bool SubroutineRef::contains(const SubroutineDecl *srDecl) const
00166 {
00167 const_iterator I = std::find(begin(), end(), srDecl);
00168 if (I != end())
00169 return true;
00170 return false;
00171 }
00172
00173 bool SubroutineRef::contains(const SubroutineType *srType) const
00174 {
00175 for (const_iterator I = begin(); I != end(); ++I) {
00176 SubroutineDecl *target = *I;
00177 if (target->getType() == srType)
00178 return true;
00179 }
00180 return false;
00181 }
00182
00183 bool SubroutineRef::keepSubroutinesWithArity(unsigned arity)
00184 {
00185 DeclVector::iterator I = decls.begin();
00186 while (I != decls.end()) {
00187 SubroutineDecl *decl = *I;
00188 if (decl->getArity() != arity)
00189 I = decls.erase(I);
00190 else
00191 ++I;
00192 }
00193 return !decls.empty();
00194 }