Fix DealII type problems.
[official-gcc/Ramakrishna.git] / libpcp / pcp.cc
blob3624a6251624381b2a35e500203f534d3c8ecd15
1 // Copyright (C) 2009 Free Software Foundation, Inc.
2 // Contributed by Jan Sjodin <jan.sjodin@amd.com>.
4 // This file is part of the Polyhedral Compilation Package Library (libpcp).
6 // Libpcp is free software; you can redistribute it and/or modify it
7 // under the terms of the GNU Lesser General Public License as published by
8 // the Free Software Foundation; either version 2.1 of the License, or
9 // (at your option) any later version.
11 // Libpcp is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14 // more details.
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with libpcp; see the file COPYING.LIB. If not, write to the
18 // Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 // MA 02110-1301, USA.
21 // As a special exception, if you link this library with other files, some
22 // of which are compiled with GCC, to produce an executable, this library
23 // does not by itself cause the resulting executable to be covered by the
24 // GNU General Public License. This exception does not however invalidate
25 // any other reasons why the executable file might be covered by the GNU
26 // General Public License.
28 #include "pcp_error.h"
29 #include "pcp_alloc.h"
30 #include "pcp.h"
31 #include "pcp_visitor.h"
33 // PCP Object
35 // Initialize
36 void
37 PcpObject::initialize()
39 setName(NULL);
40 setAnnots(NULL);
43 // Set name to NAME.
44 void
45 PcpObject::setName(const char* name)
47 this->name = name;
50 // Get name.
51 const char*
52 PcpObject::getName()
54 return this->name;
57 // Set annotation to ANNOT.
58 void
59 PcpObject::setAnnots(PcpAnnotSet* annots)
61 this->annots = annots;
64 // Get number of annotations.
65 int PcpObject::getNumAnnots()
67 return this->getAnnots() == NULL ? 0 : this->getAnnots()->getNumAnnots();
70 // Get annotation with given INDEX.
71 PcpAnnotTerm* PcpObject::getAnnot(int index)
73 pcpAssert(this->getAnnots() != NULL);
74 return this->getAnnots()->getAnnot(index);
77 // Get annotation with given TAG.
78 PcpAnnotTerm* PcpObject::getAnnotWithTag(const char* tag)
80 int numAnnots;
81 int i;
83 if(this->getAnnots() == NULL)
84 return NULL;
86 numAnnots = this->getNumAnnots();
87 for(i = 0; i < numAnnots; i++)
89 PcpAnnotTerm* annotTerm = this->getAnnot(i);
90 if(annotTerm->tagEquals(tag))
91 return annotTerm;
93 return NULL;
96 // Returns true if an annotation with given TAG exists.
97 bool
98 PcpObject::containsAnnotWithTag(const char* tag)
100 return this->getAnnotWithTag(tag) != NULL;
103 // Add ANNOT
104 void PcpObject::addAnnot(PcpAnnotTerm* annot)
106 PcpAnnotSet* annots = this->getAnnots();
107 if(annots == NULL)
109 annots = new PcpAnnotSet();
110 this->setAnnots(annots);
112 annots->addAnnot(annot);
115 // Get annotations.
116 PcpAnnotSet*
117 PcpObject::getAnnots()
119 return this->annots;
122 // Return true if this is an array type.
123 bool
124 PcpObject::isArrayType()
126 return false;
129 // Return true if this is an expr.
130 bool
131 PcpObject::isExpr()
133 return false;
136 // Return true if this is an iv.
137 bool
138 PcpObject::isIv()
140 return false;
143 // Return true if this is a parameter.
144 bool
145 PcpObject::isParameter()
147 return false;
151 // Return true if this is a bool_expr.
152 bool
153 PcpObject::isBoolExpr()
155 return false;
158 // Return true if this is a variable.
159 bool
160 PcpObject::isVariable()
162 return false;
165 // Return true if this is an array access.
166 bool
167 PcpObject::isArrayAccess()
169 return false;
172 // Return true if this is a stmt.
173 bool
174 PcpObject::isStmt()
176 return false;
179 // Return true if this is a scop.
180 bool
181 PcpObject::isScop()
183 return false;
186 // Cast this to array type.
187 PcpArrayType*
188 PcpObject::toArrayType()
190 pcpAssert(false);
191 return NULL;
194 // Cast this to expr.
195 PcpExpr*
196 PcpObject::toExpr()
198 pcpAssert(false);
199 return NULL;
202 // Cast this to parameter.
203 PcpParameter*
204 PcpObject::toParameter()
206 pcpAssert(false);
207 return NULL;
210 // Cast this to IV.
211 PcpIv*
212 PcpObject::toIv()
214 pcpAssert(false);
215 return NULL;
218 // Cast this to bool expr.
219 PcpBoolExpr*
220 PcpObject::toBoolExpr()
222 pcpAssert(false);
223 return NULL;
226 // Cast this to variable.
227 PcpVariable*
228 PcpObject::toVariable()
230 pcpAssert(false);
231 return NULL;
234 // Cast this to array access.
235 PcpArrayAccess*
236 PcpObject::toArrayAccess()
238 pcpAssert(false);
239 return NULL;
242 // Cast this to stmt.
243 PcpStmt*
244 PcpObject::toStmt()
246 pcpAssert(false);
247 return NULL;
250 // Cast this to scop.
251 PcpScop*
252 PcpObject::toScop()
254 pcpAssert(false);
255 return NULL;
258 // Set annotations array in ANNOTSet to ANNOTS.
259 void
260 PcpAnnotSet::setAnnots(PcpDynamicArray<PcpAnnotTerm*>* annots)
262 this->annots = annots;
265 // Get annotation array in ANNOTSet.
266 PcpDynamicArray<PcpAnnotTerm*>*
267 PcpAnnotSet::getAnnots()
269 return this->annots;
272 // Get the annotation in ANNOTSet with given INDEX.
273 PcpAnnotTerm* PcpAnnotSet::getAnnot(int index)
275 PcpAnnotTerm* result = this->getAnnots()->get(index);
276 return result;
279 // Get number of annotations in ANNOTSet.
280 int
281 PcpAnnotSet::getNumAnnots()
283 return this->getAnnots()->getSize();
286 // Get the annotation with TAG in ANNOTSet.
287 PcpAnnotTerm* PcpAnnotSet::getAnnotWithTag(const char* tag)
289 int i;
290 int numAnnots = this->getNumAnnots();
291 for(i = 0; i < numAnnots; i++)
293 PcpAnnotTerm* annotTerm = this->getAnnot(i);
294 const char* annotTag = annotTerm->getTag();
295 if(strcmp(annotTag, tag) == 0)
296 return annotTerm;
298 return NULL;
301 // Add ANNOT to ANNOTSet. Assert that no previous annotation with the
302 // same tag exists.
303 void
304 PcpAnnotSet::addAnnot(PcpAnnotTerm* annot)
306 PcpAnnotTerm* existingTerm = this->getAnnotWithTag(annot->getTag());
307 if(existingTerm != NULL)
309 pcpAssert(false);
310 printf("Existing tag: %s\n", annot->getTag());
313 this->getAnnots()->add(annot);
316 PcpAnnotSet::PcpAnnotSet()
318 PcpDynamicArray<PcpAnnotTerm*>* annots =
319 new PcpDynamicArray<PcpAnnotTerm*>(1);
320 this->setAnnots(annots);
323 void
324 PcpAnnotSet::accept(PcpVisitor* visitor)
326 visitor->visit(this);
329 // Return true if ANNOT is an int.
330 bool
331 PcpAnnot::isAnnotInt()
333 return false;
336 // Return true if ANNOT is a string.
337 bool
338 PcpAnnot::isAnnotString()
340 return false;
343 // Return true if ANNOT is an object.
344 bool
345 PcpAnnot::isAnnotObject()
347 return false;
350 // Return true if ANNOT is a term.
351 bool
352 PcpAnnot::isAnnotTerm()
354 return false;
357 // Cast ANNOT to int.
358 PcpAnnotInt*
359 PcpAnnot::toAnnotInt()
361 pcpAssert(false);
362 return NULL;
365 // Cast ANNOT to string.
366 PcpAnnotString*
367 PcpAnnot::toAnnotString()
369 pcpAssert(false);
370 return NULL;
373 // Cast ANNOT to object.
374 PcpAnnotObject*
375 PcpAnnot::toAnnotObject()
377 pcpAssert(false);
378 return NULL;
381 // Cast ANNOT to term.
382 PcpAnnotTerm*
383 PcpAnnot::toAnnotTerm()
385 pcpAssert(false);
386 return NULL;
389 // Set value of ANNOTInt to VALUE.
390 void
391 PcpAnnotInt::setValue(int value)
393 this->value = value;
396 // Get value of ANNOTInt.
398 PcpAnnotInt::getValue()
400 return this->value;
403 // Create annot int with given VALUE.
404 PcpAnnotInt::PcpAnnotInt(int value)
406 this->setValue(value);
409 bool
410 PcpAnnotInt::isAnnotInt()
412 return true;
415 PcpAnnotInt*
416 PcpAnnotInt::toAnnotInt()
418 return this;
421 void
422 PcpAnnotInt::accept(PcpVisitor* visitor)
424 visitor->visit(this);
427 // PcpAnnotString
428 bool PcpAnnotString::isAnnotString()
430 return true;
432 PcpAnnotString* PcpAnnotString::toAnnotString()
434 return this;
437 // Set string of ANNOTString to STRING.
438 void
439 PcpAnnotString::setString(const char* string)
441 this->string = string;
444 // Get string of ANNOTString.
445 const char*
446 PcpAnnotString::getString()
448 return this->string;
451 // Create annot string with given STRING.
452 PcpAnnotString::PcpAnnotString(const char* string)
454 this->setString(string);
457 void
458 PcpAnnotString::accept(PcpVisitor* visitor)
460 visitor->visit(this);
463 // PCP Annot Object
465 bool PcpAnnotObject::isAnnotObject()
467 return true;
470 PcpAnnotObject* PcpAnnotObject::toAnnotObject()
472 return this;
475 // Set object to OBJECT.
476 void
477 PcpAnnotObject::setObject(PcpObject* object)
479 this->object = object;
482 // Get object.
483 PcpObject*
484 PcpAnnotObject::getObject()
486 return this->object;
489 // Create annot object with given OBJECT.
490 PcpAnnotObject::PcpAnnotObject(PcpObject* object)
492 this->setObject(object);
495 void
496 PcpAnnotObject::accept(PcpVisitor* visitor)
498 visitor->visit(this);
501 // Pcp Annot Term
503 // Return true if this is an annot term.
504 bool PcpAnnotTerm::isAnnotTerm()
506 return true;
509 // Convert this to an annot term.
510 PcpAnnotTerm* PcpAnnotTerm::toAnnotTerm()
512 return this;
515 // Set tag to TAG.
516 void
517 PcpAnnotTerm::setTag(const char* tag)
519 this->tag = tag;
522 // Get tag.
523 const char*
524 PcpAnnotTerm::getTag()
526 return this->tag;
529 // Return true if tag equals TAG.
530 bool
531 PcpAnnotTerm::tagEquals(const char* tag)
533 return strcmp(tag, this->getTag()) == 0;
536 // Get number of arguments.
538 PcpAnnotTerm::getNumArguments()
540 return this->getArguments()->getSize();
543 // Set arguments to ARGUMENTS.
544 void
545 PcpAnnotTerm::setArguments(PcpArray<PcpAnnot*>* arguments)
547 this->arguments = arguments;
550 // Get arguments.
551 PcpArray<PcpAnnot*>*
552 PcpAnnotTerm::getArguments()
554 return this->arguments;
557 // Set argument with given INDENT to ANNOT.
558 void
559 PcpAnnotTerm::setArgument(int index, PcpAnnot* annot)
561 this->getArguments()->set(index, annot);
564 // Get argument with given INDEX.
565 PcpAnnot*
566 PcpAnnotTerm::getArgument(int index)
568 return this->getArguments()->get(index);
571 // Create annot term with TAG, and ARGUMENTS.
572 PcpAnnotTerm::PcpAnnotTerm(const char* tag, PcpArray<PcpAnnot*>* arguments)
574 this->setTag(tag);
575 this->setArguments(arguments);
578 void
579 PcpAnnotTerm::accept(PcpVisitor* visitor)
581 visitor->visit(this);
584 // PCP Annot Term Builder
586 // Set tag to TAG.
587 void
588 PcpAnnotTermBuilder::setTag(const char* tag)
590 this->tag = tag;
593 // Get tag.
594 const char*
595 PcpAnnotTermBuilder::getTag()
597 return this->tag;
600 // Set arguments to ARGUMENTS.
601 void
602 PcpAnnotTermBuilder::setArguments(PcpDynamicArray<PcpAnnot*>* arguments)
604 this->arguments = arguments;
607 // Get arguments.
608 PcpDynamicArray<PcpAnnot*>*
609 PcpAnnotTermBuilder::getArguments()
611 return this->arguments;
614 // Add ARGUMENT.
615 void
616 PcpAnnotTermBuilder::addArgument(PcpAnnot* argument)
618 this->getArguments()->add(argument);
621 // Create new annot term builder.
622 PcpAnnotTermBuilder::PcpAnnotTermBuilder()
624 this->setTag(NULL);
625 this->setArguments(new PcpDynamicArray<PcpAnnot*>(1));
628 // Create annot term.
629 PcpAnnotTerm*
630 PcpAnnotTermBuilder::createAnnot()
632 PcpAnnotTerm* annotTerm;
633 annotTerm = new PcpAnnotTerm(this->getTag(), this->getArguments());
634 return annotTerm;
637 // Pcp Array Type
639 // Return true if this is an array type.
640 bool
641 PcpArrayType::isArrayType()
643 return true;
646 // Cast this to array type.
647 PcpArrayType*
648 PcpArrayType::toArrayType()
650 return this;
653 // Return the number of dimensions.
655 PcpArrayType::getNumDimensions()
657 return this->getDimensions()->getSize();
660 // Set the dimensions to DIMENSIONS.
661 void
662 PcpArrayType::setDimensions(PcpArray<PcpExpr*>* dimensions)
664 this->dimensions = dimensions;
667 // Get dimensions.
668 PcpArray<PcpExpr*>*
669 PcpArrayType::getDimensions()
671 return this->dimensions;
674 // Return the size of dimension with given INDEX
675 PcpExpr*
676 PcpArrayType::getDimension(int index)
678 return this->getDimensions()->get(index);
681 // Get iterator over the dimensions.
682 PcpIterator<PcpExpr*>*
683 PcpArrayType::getDimensionsIterator()
685 return this->getDimensions()->getIterator();
688 // Create new array type.
689 PcpArrayType::PcpArrayType(PcpArray<PcpExpr*>* dimensions)
691 initialize();
692 this->setDimensions(dimensions);
695 void
696 PcpArrayType::accept(PcpVisitor* visitor)
698 visitor->visit(this);
701 // Pcp Array Type Builder
703 // Set array to ARRAY.
704 void
705 PcpArrayTypeBuilder::setArray(PcpDynamicArray<PcpExpr*>* array)
707 this->array = array;
710 // Get array.
711 PcpDynamicArray<PcpExpr*>*
712 PcpArrayTypeBuilder::getArray()
714 return this->array;
717 // Create array type builder.
718 PcpArrayTypeBuilder::PcpArrayTypeBuilder()
720 this->setArray(new PcpDynamicArray<PcpExpr*>(2));
723 // Add a new dimension with the given SIZE.
724 void
725 PcpArrayTypeBuilder::addDimension(PcpExpr* size)
727 this->getArray()->add(size);
730 // Add a new dimension with given SIZE
731 void
732 PcpArrayTypeBuilder::addIntDimension(int size)
734 this->addDimension(new PcpConstant(size));
737 // Create new array type from BUIDER.
738 PcpArrayType*
739 PcpArrayTypeBuilder::createType()
741 return new PcpArrayType(this->getArray());
744 // PcpExpr
746 // Return true if this is an expr.
747 bool PcpExpr::isExpr()
749 return true;
752 // Convert this to an expr.
753 PcpExpr* PcpExpr::toExpr()
755 return this;
758 // Return true if this is a pcpParameter, otherwise return false.
759 bool
760 PcpExpr::isParameter()
762 return false;
765 // Return true if this is a pcpArith, otherwise return false.
766 bool
767 PcpExpr::isArith()
769 return false;
772 // Return true if this is a pcpConstant, otherwise return false.
773 bool
774 PcpExpr::isConstant()
776 return false;
779 // Return true if this is a pcpIv, otherwise return false.
780 bool
781 PcpExpr::isIv()
783 return false;
786 // Cast this to pcpParameter.
787 PcpParameter*
788 PcpExpr::toParameter()
790 pcpAssert(false);
791 return NULL;
794 // Cast this to pcpArith.
795 PcpArith*
796 PcpExpr::toArith()
798 pcpAssert(false);
799 return NULL;
802 // Cast this to pcpConstant.
803 PcpConstant*
804 PcpExpr::toConstant()
806 pcpAssert(false);
807 return NULL;
810 // Cast this to pcpIv.
811 PcpIv*
812 PcpExpr::toIv()
814 pcpAssert(false);
815 return NULL;
818 // PCP Bool Expr
820 // Return true if this is a bool expr.
821 bool
822 PcpBoolExpr::isBoolExpr()
824 return true;
827 // Cast this to a bool expr.
828 PcpBoolExpr* PcpBoolExpr::toBoolExpr()
830 return this;
833 // Return true if this is a compare.
834 bool
835 PcpBoolExpr::isCompare()
837 return false;
840 // Return true if this is a boolean arithmetic operation.
841 bool
842 PcpBoolExpr::isBoolArith()
844 return false;
847 // Convert this to a compare.
848 PcpCompare*
849 PcpBoolExpr::toCompare()
851 pcpAssert(false);
852 return NULL;
855 // Cast BOOLExpr to bool arith, if it is not a boolean arithmetic operator return NULL.
856 PcpBoolArith*
857 PcpBoolExpr::toBoolArith()
859 pcpAssert(false);
860 return NULL;
864 // PCP Compare
866 // Return true if this is a compare.
867 bool
868 PcpCompare::isCompare()
870 return true;
873 // Convert this to a compare.
874 PcpCompare*
875 PcpCompare::toCompare()
877 return this;
880 // Set operator to OPER.
881 void
882 PcpCompare::setOperator(PcpCompareOperator oper)
884 this->oper = oper;
887 // Get operator.
888 PcpCompareOperator
889 PcpCompare::getOperator()
891 return this->oper;
894 // Set lhs to LHS.
895 void
896 PcpCompare::setLhs(PcpExpr* lhs)
898 this->lhs = lhs;
901 // Get lhs.
902 PcpExpr*
903 PcpCompare::getLhs()
905 return this->lhs;
908 // Set rhs to RHS.
909 void
910 PcpCompare::setRhs(PcpExpr* rhs)
912 this->rhs = rhs;
915 // Get rhs.
916 PcpExpr*
917 PcpCompare::getRhs()
919 return this->rhs;
922 // Create new compare with given OPER, LHS and RHS
923 PcpCompare::PcpCompare(PcpCompareOperator oper,
924 PcpExpr* lhs,
925 PcpExpr* rhs)
927 initialize();
928 this->setOperator(oper);
929 this->setLhs(lhs);
930 this->setRhs(rhs);
933 void
934 PcpCompare::accept(PcpVisitor* visitor)
936 visitor->visit(this);
939 // PCP Bool Arith
941 // Return true if this is a bool arith
942 bool PcpBoolArith::isBoolArith()
944 return true;
947 // Convert this to a bool arith.
948 PcpBoolArith* PcpBoolArith::toBoolArith()
950 return this;
954 // Set operator to OPERATOR.
955 void
956 PcpBoolArith::setOperator(PcpBoolArithOperator oper)
958 this->oper = oper;
961 // Get operator.
962 PcpBoolArithOperator
963 PcpBoolArith::getOperator()
965 return this->oper;
968 // Get number of operands.
970 PcpBoolArith::getNumOperands()
972 return this->getOperands()->getSize();
975 // Set operands to OPERANDS.
976 void
977 PcpBoolArith::setOperands(PcpArray<PcpBoolExpr*>* operands)
979 this->operands = operands;
982 // Get operands.
983 PcpArray<PcpBoolExpr*>*
984 PcpBoolArith::getOperands()
986 return this->operands;
989 // Get operand with given INDEX.
990 PcpBoolExpr*
991 PcpBoolArith::getOperand(int index)
993 return this->getOperands()->get(index);
996 PcpIterator<PcpBoolExpr*>*
997 PcpBoolArith::getOperandsIterator()
999 return this->getOperands()->getIterator();
1003 // Create new boolean arithmetic operation.
1004 PcpBoolArith::PcpBoolArith(PcpBoolArithOperator oper,
1005 PcpArray<PcpBoolExpr*>* operands)
1007 initialize();
1008 this->setOperator(oper);
1009 this->setOperands(operands);
1012 void
1013 PcpBoolArith::accept(PcpVisitor* visitor)
1015 visitor->visit(this);
1018 // PCP Bool Arith Builder.
1020 // Set operator to OPERATOR.
1021 void
1022 PcpBoolArithBuilder::setOperator(PcpBoolArithOperator oper)
1024 this->oper = oper;
1027 // Get operator.
1028 PcpBoolArithOperator
1029 PcpBoolArithBuilder::getOperator()
1031 return this->oper;
1034 // Set operands to OPERANDS.
1035 void
1036 PcpBoolArithBuilder::setOperands(PcpDynamicArray<PcpBoolExpr*>* operands)
1038 this->operands = operands;
1041 // Get operands.
1042 PcpDynamicArray<PcpBoolExpr*>*
1043 PcpBoolArithBuilder::getOperands()
1045 return this->operands;
1048 // Add OPERAND.
1049 void
1050 PcpBoolArithBuilder::addOperand(PcpBoolExpr* operand)
1052 this->getOperands()->add(operand);
1055 // Create new boolean arithmetic operation builder.
1056 PcpBoolArithBuilder::PcpBoolArithBuilder()
1058 this->setOperator(PcpBoolArithOperator::unknown());
1059 this->setOperands(new PcpDynamicArray<PcpBoolExpr*>(2));
1063 // Create new boolean arithmetic operation.
1064 PcpBoolArith*
1065 PcpBoolArithBuilder::createBoolArith()
1067 PcpBoolArith* boolArith;
1068 boolArith = new PcpBoolArith(this->getOperator(), this->getOperands());
1069 return boolArith;
1073 // Create binary arithmetic operation with OPERATOR, LHS, RHS.
1074 PcpBoolArith*
1075 PcpBoolArith::pcpBoolArithBinaryCreate(PcpBoolArithOperator oper,
1076 PcpBoolExpr* lhs,
1077 PcpBoolExpr* rhs)
1079 PcpBoolArith* result;
1080 PcpBoolArithBuilder* builder = new PcpBoolArithBuilder();
1081 builder->setOperator(oper);
1082 builder->addOperand(lhs);
1083 builder->addOperand(rhs);
1084 result = builder->createBoolArith();
1085 delete builder;
1086 return result;
1089 // Set operator of ARITH to OPERATOR.
1091 // Return true if this is an arithmetic operation.
1092 bool PcpArith::isArith()
1094 return true;
1097 // Cast this to an arithmetic operation.
1098 PcpArith* PcpArith::toArith()
1100 return this;
1103 // Set operator to OPER.
1104 void
1105 PcpArith::setOperator(PcpArithOperator oper)
1107 this->oper = oper;
1110 // Get operator of ARITH.
1111 PcpArithOperator
1112 PcpArith::getOperator()
1114 return this->oper;
1117 // Get number of operands.
1118 int PcpArith::getNumOperands()
1120 return this->getOperands()->getSize();
1123 // Set operands to OPERANDS.
1124 void
1125 PcpArith::setOperands(PcpArray<PcpExpr*>* operands)
1127 this->operands = operands;
1130 // Get operands of ARITH.
1131 PcpArray<PcpExpr*>*
1132 PcpArith::getOperands()
1134 return this->operands;
1137 // Get operand with given INDEX.
1138 PcpExpr*
1139 PcpArith::getOperand(int index)
1141 return this->getOperands()->get(index);
1144 PcpIterator<PcpExpr*>*
1145 PcpArith::getOperandsIterator()
1147 return this->getOperands()->getIterator();
1151 // Create new arithmetic operation.
1152 PcpArith::PcpArith(PcpArithOperator oper, PcpArray<PcpExpr*>* operands)
1154 initialize();
1155 this->setOperator(oper);
1156 this->setOperands(operands);
1159 // Create binary arithmetic operation with OPERATOR, LHS, RHS.
1160 PcpArith*
1161 PcpArith::pcpArithBinaryCreate(PcpArithOperator oper,
1162 PcpExpr* lhs,
1163 PcpExpr* rhs)
1165 PcpArith* arith;
1166 PcpArithBuilder* builder = new PcpArithBuilder();
1167 builder->setOperator(oper);
1168 builder->addOperand(lhs);
1169 builder->addOperand(rhs);
1170 arith = builder->createArith();
1171 delete builder;
1172 return arith;
1175 void
1176 PcpArith::accept(PcpVisitor* visitor)
1178 visitor->visit(this);
1182 // PCP Arith Builder.
1184 // Set operator to OPERATOR.
1185 void
1186 PcpArithBuilder::setOperator(PcpArithOperator oper)
1188 this->oper = oper;
1191 // Get operator.
1192 PcpArithOperator
1193 PcpArithBuilder::getOperator()
1195 return this->oper;
1198 // Set operands to OPERANDS.
1199 void
1200 PcpArithBuilder::setOperands(PcpDynamicArray<PcpExpr*>* operands)
1202 this->operands = operands;
1205 // Get operands.
1206 PcpDynamicArray<PcpExpr*>*
1207 PcpArithBuilder::getOperands()
1209 return this->operands;
1212 // Add OPERAND.
1213 void
1214 PcpArithBuilder::addOperand(PcpExpr* operand)
1216 this->getOperands()->add(operand);
1219 // Create new arithmetic operation.
1220 PcpArith*
1221 PcpArithBuilder::createArith()
1223 PcpArith* arith;
1224 arith = new PcpArith(this->getOperator(), this->getOperands());
1225 return arith;
1228 // Create new arithmetic operation builder.
1229 PcpArithBuilder::PcpArithBuilder()
1231 this->setOperator(PcpArithOperator::unknown());
1232 this->setOperands(new PcpDynamicArray<PcpExpr*>(2));
1235 // PCP Constant
1237 // Set value of CONSTANT to VALUE.
1238 void
1239 PcpConstant::setValue(int value)
1241 this->value = value;
1244 // Get value of CONSTANT.
1246 PcpConstant::getValue()
1248 return this->value;
1251 // Return true if this is a constant.
1252 bool
1253 PcpConstant::isConstant()
1255 return true;
1258 // Cast this to a constant.
1259 PcpConstant*
1260 PcpConstant::toConstant()
1262 return this;
1265 // Create constant with VALUE.
1266 PcpConstant::PcpConstant(int value)
1268 initialize();
1269 this->setValue(value);
1272 void
1273 PcpConstant::accept(PcpVisitor* visitor)
1275 visitor->visit(this);
1278 // PCP Induction Variable
1280 // Return true if this is an iv.
1281 bool
1282 PcpIv::isIv()
1284 return true;
1287 // Convert this to an iv.
1288 PcpIv*
1289 PcpIv::toIv()
1291 return this;
1294 // Create iv with NAME.
1295 PcpIv::PcpIv(const char* name)
1297 initialize();
1298 this->setName(name);
1301 void
1302 PcpIv::accept(PcpVisitor* visitor)
1304 visitor->visit(this);
1307 // PCP Variable
1309 // Return true if this is a variable.
1310 bool PcpVariable::isVariable()
1312 return true;
1315 // Cast this to a variable.
1316 PcpVariable* PcpVariable::toVariable()
1318 return this;
1321 // Set is input of to ISINPUT.
1322 void
1323 PcpVariable::setIsInput(bool isInput)
1325 this->isInput = isInput;
1328 // Get is input
1329 bool
1330 PcpVariable::getIsInput()
1332 return this->isInput;
1335 // Set is output to ISOUTPUT.
1336 void
1337 PcpVariable::setIsOutput(bool isOutput)
1339 this->isOutput = isOutput;
1342 // Get is output.
1343 bool
1344 PcpVariable::getIsOutput()
1346 return this->isOutput;
1349 // Set type to TYPE.
1350 void
1351 PcpVariable::setType(PcpArrayType* type)
1353 this->type = type;
1356 // Get tpe.
1357 PcpArrayType*
1358 PcpVariable::getType()
1360 return this->type;
1363 // Create variable given TYPE and NAME.
1364 PcpVariable::PcpVariable(PcpArrayType* type, const char* name)
1366 initialize();
1367 this->setType(type);
1368 this->setName(name);
1369 this->setIsInput(false);
1370 this->setIsOutput(false);
1373 void
1374 PcpVariable::accept(PcpVisitor* visitor)
1376 visitor->visit(this);
1379 // PCP Parameter
1381 // Return true if this is a parameter.
1382 bool PcpParameter::isParameter()
1384 return true;
1387 // Cast this to a parameter.
1388 PcpParameter* PcpParameter::toParameter()
1390 return this;
1393 // Create parameter with the given NAME.
1394 PcpParameter::PcpParameter(const char* name)
1396 initialize();
1397 this->setName(name);
1400 void
1401 PcpParameter::accept(PcpVisitor* visitor)
1403 visitor->visit(this);
1406 // Array Access.
1408 // Return true if this is an array access
1409 bool PcpArrayAccess::isArrayAccess()
1411 return true;
1414 // Cast this to an array access.
1415 PcpArrayAccess*
1416 PcpArrayAccess::toArrayAccess()
1418 return this;
1421 // Set operator to OPERATOR.
1422 void
1423 PcpArrayAccess::setOperator(PcpArrayOperator oper)
1425 this->oper = oper;
1428 // Get operator.
1429 PcpArrayOperator
1430 PcpArrayAccess::getOperator()
1432 return this->oper;
1435 // Set base to BASE.
1436 void
1437 PcpArrayAccess::setBase(PcpVariable* base)
1439 this->base = base;
1442 // Get base.
1443 PcpVariable*
1444 PcpArrayAccess::getBase()
1446 return this->base;
1449 // Set subscripts to SUBSCRIPTS.
1450 void
1451 PcpArrayAccess::setSubscripts(PcpArray<PcpExpr*>* subscripts)
1453 this->subscripts = subscripts;
1456 // Get subscripts.
1457 PcpArray<PcpExpr*>*
1458 PcpArrayAccess::getSubscripts()
1460 return this->subscripts;
1463 // Set subscript at INDEX to SUBSCRIPT.
1464 void
1465 PcpArrayAccess::setSubscript(int index, PcpExpr* subscript)
1467 this->getSubscripts()->set(index, subscript);
1470 // Get subscript at INDEX.
1471 PcpExpr*
1472 PcpArrayAccess::getSubscript(int index)
1474 return this->getSubscripts()->get(index);
1477 // Get number of subscripts.
1479 PcpArrayAccess::getNumSubscripts()
1481 PcpVariable* variable = this->getBase();
1482 PcpArrayType* type = variable->getType();
1483 int typeNumDims = type->getNumDimensions();
1484 return typeNumDims;
1487 PcpIterator<PcpExpr*>*
1488 PcpArrayAccess::getSubscriptsIterator()
1490 return this->getSubscripts()->getIterator();
1494 // Create array access given OPERATOR, BASE and SUBSCRIPTS.
1495 PcpArrayAccess::PcpArrayAccess(PcpArrayOperator oper,
1496 PcpVariable* base,
1497 PcpArray<PcpExpr*>* subscripts)
1499 initialize();
1500 this->setOperator(oper);
1501 this->setBase(base);
1502 this->setSubscripts(subscripts);
1505 void
1506 PcpArrayAccess::accept(PcpVisitor* visitor)
1508 visitor->visit(this);
1511 // Return true if this is a use, otherwise return false.
1512 bool
1513 PcpArrayAccess::isUse()
1515 return this->getOperator().isUse();
1518 // Return true if this is a def, otherwise return false.
1519 bool
1520 PcpArrayAccess::isDef()
1522 return this->getOperator().isDef();
1525 // Return true if this is a maydef, otherwise return false.
1526 bool
1527 PcpArrayAccess::isMaydef()
1529 return this->getOperator().isMaydef();
1532 // PCP Array Access Builder
1534 // Set base to BASE.
1535 void
1536 PcpArrayAccessBuilder::setBase(PcpVariable* base)
1538 this->base = base;
1541 // Get base.
1542 PcpVariable*
1543 PcpArrayAccessBuilder::getBase()
1545 return this->base;
1548 // Set operator to OPERATOR.
1549 void
1550 PcpArrayAccessBuilder::setOperator(PcpArrayOperator oper)
1552 this->oper = oper;
1555 // Get operator.
1556 PcpArrayOperator
1557 PcpArrayAccessBuilder::getOperator()
1559 return this->oper;
1562 // Set subscript index to SUBSCRIPTINDEX.
1563 void
1564 PcpArrayAccessBuilder::setSubscriptIndex(int subscriptIndex)
1566 this->subscriptIndex = subscriptIndex;
1569 // Get subscript index.
1571 PcpArrayAccessBuilder::getSubscriptIndex()
1573 return this->subscriptIndex;
1576 // Get subscripts.
1577 PcpArray<PcpExpr*>*
1578 PcpArrayAccessBuilder::getSubscripts()
1580 return this->subscripts;
1583 // Set subscript with given INDEX to SUBSCRIPT.
1584 void
1585 PcpArrayAccessBuilder::setSubscript(int index, PcpExpr* subscript)
1587 this->getSubscripts()->set(index, subscript);
1591 // Set subscripts to SUBSCRIPTS.
1592 void
1593 PcpArrayAccessBuilder::setSubscripts(PcpArray<PcpExpr*>* subscripts)
1595 this->subscripts = subscripts;
1598 // Get subscript with given INDEX.
1599 PcpExpr*
1600 PcpArrayAccessBuilder::getSubscript(int index)
1602 return this->getSubscripts()->get(index);
1605 // Get number of dimensions of base.
1607 PcpArrayAccessBuilder::getBaseNumDimensions()
1609 PcpVariable* variable = this->getBase();
1610 PcpArrayType* type = variable->getType();
1611 int typeNumDims = type->getNumDimensions();
1612 return typeNumDims;
1615 // Add SUBSCRIPT.
1616 void
1617 PcpArrayAccessBuilder::addSubscript(PcpExpr* subscript)
1619 int currentIndex = this->getSubscriptIndex();
1620 int typeNumDims = this->getBaseNumDimensions();
1622 pcpAssert(currentIndex < typeNumDims);
1623 this->setSubscript(currentIndex, subscript);
1624 this->setSubscriptIndex(currentIndex + 1);
1628 // Create new access builder with given BASE.
1629 PcpArrayAccessBuilder::PcpArrayAccessBuilder(PcpVariable* base)
1631 PcpArrayType* type = base->getType();
1632 PcpArray<PcpExpr*>* subscripts = new PcpArray<PcpExpr*>(type->getNumDimensions());
1634 this->setBase(base);
1635 this->setOperator(PcpArrayOperator::unknown());
1636 this->setSubscriptIndex(0);
1637 this->setSubscripts(subscripts);
1640 // Create array access.
1641 PcpArrayAccess*
1642 PcpArrayAccessBuilder::createAccess()
1644 pcpAssert(!this->getOperator().isUnknown());
1645 pcpAssert(this->getSubscriptIndex() == this->getBaseNumDimensions());
1646 return new PcpArrayAccess(this->getOperator(),
1647 this->getBase(),
1648 this->getSubscripts());
1651 // PCP Stmt
1653 // Return true if this is a statement
1654 bool
1655 PcpStmt::isStmt()
1657 return true;
1660 // Cast this to a statement.
1661 PcpStmt* PcpStmt::toStmt()
1663 return this;
1666 // Returns true if this is a copy stmt.
1667 bool
1668 PcpStmt::isCopy()
1670 return false;
1673 // Returns true if this is a user stmt.
1674 bool
1675 PcpStmt::isUserStmt()
1677 return false;
1680 // Returns true if this is a loop stmt.
1681 bool
1682 PcpStmt::isLoop()
1684 return false;
1687 // Returns true if this is a guard stmt.
1688 bool
1689 PcpStmt::isGuard()
1691 return false;
1694 // Returns true if this is a sequence stmt.
1695 bool
1696 PcpStmt::isSequence()
1698 return false;
1701 // Cast this to copy stmt
1702 PcpCopy*
1703 PcpStmt::toCopy()
1705 pcpAssert(false);
1706 return NULL;
1709 // Cast this to user stmt
1710 PcpUserStmt*
1711 PcpStmt::toUserStmt()
1713 pcpAssert(false);
1714 return NULL;
1717 // Cast this to guard stmt
1718 PcpGuard*
1719 PcpStmt::toGuard()
1721 pcpAssert(false);
1722 return NULL;
1725 // Cast this to loop stmt
1726 PcpLoop*
1727 PcpStmt::toLoop()
1729 pcpAssert(false);
1730 return NULL;
1733 // Cast this to sequence stmt
1734 PcpSequence*
1735 PcpStmt::toSequence()
1737 pcpAssert(false);
1738 return NULL;
1741 // PCP Copy Stmt
1743 // Return true if this is a copy.
1744 bool PcpCopy::isCopy()
1746 return true;
1749 // Cast this to a copy.
1750 PcpCopy* PcpCopy::toCopy()
1752 return this;
1755 // Set source to SRC.
1756 void
1757 PcpCopy::setSrc(PcpArrayAccess* src)
1759 this->src = src;
1762 // Get source.
1763 PcpArrayAccess*
1764 PcpCopy::getSrc()
1766 return this->src;
1769 // Set destination to DEST.
1770 void
1771 PcpCopy::setDest(PcpArrayAccess* dest)
1773 this->dest = dest;
1776 // Get destination.
1777 PcpArrayAccess*
1778 PcpCopy::getDest()
1780 return this->dest;
1783 // Create new copy statement given DEST and SRC.
1784 PcpCopy::PcpCopy(PcpArrayAccess* dest, PcpArrayAccess* src)
1786 initialize();
1787 this->setDest(dest);
1788 this->setSrc(src);
1791 void
1792 PcpCopy::accept(PcpVisitor* visitor)
1794 visitor->visit(this);
1797 // PCP User Stmt
1799 // Return true if this is a user stmt.
1800 bool PcpUserStmt::isUserStmt()
1802 return true;
1805 // Cast this to a user stmt.
1806 PcpUserStmt* PcpUserStmt::toUserStmt()
1808 return this;
1811 // Get numer of accessses in USERStmt.
1813 PcpUserStmt::getNumAccesses()
1815 return this->getArrayAccesses()->getSize();
1818 // Set array accesses of USERStmt to ACCESSSES.
1819 void
1820 PcpUserStmt::setArrayAccesses(PcpArray<PcpArrayAccess*>* accesses)
1822 this->accesses = accesses;
1825 // Get array accesses of USERStmt.
1826 PcpArray<PcpArrayAccess*>*
1827 PcpUserStmt::getArrayAccesses()
1829 return this->accesses;
1832 // Set array access in USERStmt with given INDEX to ACCESS.
1833 void
1834 PcpUserStmt::setArrayAccess(int index, PcpArrayAccess* access)
1836 this->getArrayAccesses()->set(index, access);
1839 // Get array access in USERStmt with given INDEX.
1840 PcpArrayAccess*
1841 PcpUserStmt::getArrayAccess(int index)
1843 return this->getArrayAccesses()->get(index);
1846 PcpIterator<PcpArrayAccess*>*
1847 PcpUserStmt::getArrayAccessesIterator()
1849 return this->getArrayAccesses()->getIterator();
1852 // Create new user stmt with given NAME and ACCESSES.
1853 PcpUserStmt::PcpUserStmt(const char* name,
1854 PcpArray<PcpArrayAccess*>* accesses)
1856 this->initialize();
1857 this->setName(name);
1858 this->setArrayAccesses(accesses);
1861 void
1862 PcpUserStmt::accept(PcpVisitor* visitor)
1864 visitor->visit(this);
1867 // PCP User Stmt Builder
1869 // Set name to NAME.
1870 void
1871 PcpUserStmtBuilder::setName(const char* name)
1873 this->name = name;
1876 // Get name.
1877 const char*
1878 PcpUserStmtBuilder::getName()
1880 return this->name;
1883 // Set accesses to ACCESSES.
1884 void
1885 PcpUserStmtBuilder::setAccesses(PcpDynamicArray<PcpArrayAccess*>* accesses)
1887 this->accesses = accesses;
1890 // Get accesses.
1891 PcpDynamicArray<PcpArrayAccess*>*
1892 PcpUserStmtBuilder::getAccesses()
1894 return this->accesses;
1897 // Add ACCESS.
1898 void
1899 PcpUserStmtBuilder::addAccess(PcpArrayAccess* access)
1901 this->getAccesses()->add(access);
1904 // Create stmt builder.
1905 PcpUserStmtBuilder::PcpUserStmtBuilder()
1907 this->setName(NULL);
1908 this->setAccesses(new PcpDynamicArray<PcpArrayAccess*>(2));
1912 // Create user stmt.
1913 PcpUserStmt*
1914 PcpUserStmtBuilder::createUserStmt()
1916 PcpUserStmt* userStmt;
1917 pcpAssert(this->getName() != NULL);
1918 userStmt = new PcpUserStmt(this->getName(),this->getAccesses());
1919 return userStmt;
1922 // PCP Sequence
1924 // Return true if this is a sequence.
1925 bool PcpSequence::isSequence()
1927 return true;
1930 // Cast this to a sequence.
1931 PcpSequence* PcpSequence::toSequence()
1933 return this;
1936 // Get number of statements.
1938 PcpSequence::getNumStmts()
1940 return this->getStmts()->getSize();
1943 // Set stmts to STMTS.
1944 void
1945 PcpSequence::setStmts(PcpArray<PcpStmt*>* stmts)
1947 this->stmts = stmts;
1950 // Get stmts.
1951 PcpArray<PcpStmt*>*
1952 PcpSequence::getStmts()
1954 return this->stmts;
1957 // Set statement with given INDEX to STMT.
1958 void
1959 PcpSequence::setStmt(int index, PcpStmt* stmt)
1961 this->getStmts()->set(index, stmt);
1964 // Get statment with given INDEX.
1965 PcpStmt*
1966 PcpSequence::getStmt(int index)
1968 return this->getStmts()->get(index);
1971 PcpIterator<PcpStmt*>*
1972 PcpSequence::getStmtsIterator()
1974 return this->getStmts()->getIterator();
1978 // Create Sequence with STMTS
1979 PcpSequence::PcpSequence(PcpArray<PcpStmt*>* stmts)
1981 initialize();
1982 this->setStmts(stmts);
1985 void
1986 PcpSequence::accept(PcpVisitor* visitor)
1988 visitor->visit(this);
1990 // PCP Sequence Builder
1992 // Set stmts to STMTS.
1993 void
1994 PcpSequenceBuilder::setStmts(PcpDynamicArray<PcpStmt*>* stmts)
1996 this->stmts = stmts;
1999 // Get stmts.
2000 PcpDynamicArray<PcpStmt*>*
2001 PcpSequenceBuilder::getStmts()
2003 return this->stmts;
2006 // Add STMT to the end of the sequence.
2007 void
2008 PcpSequenceBuilder::add(PcpStmt* stmt)
2010 this->getStmts()->add(stmt);
2013 // Create sequence builder.
2014 PcpSequenceBuilder::PcpSequenceBuilder()
2016 this->setStmts(new PcpDynamicArray<PcpStmt*>(3));
2019 // Create sequence.
2020 PcpSequence*
2021 PcpSequenceBuilder::createSequence()
2023 PcpSequence* sequence;
2024 sequence = new PcpSequence(this->getStmts());
2025 return sequence;
2028 // PCP Guard
2030 // Return true if this is a guard.
2031 bool PcpGuard::isGuard()
2033 return true;
2036 // Cast this to a guard.
2037 PcpGuard* PcpGuard::toGuard()
2039 return this;
2042 // Set condition to CONDITION.
2043 void
2044 PcpGuard::setCondition(PcpBoolExpr* condition)
2046 this->condition = condition;
2049 // Get condition.
2050 PcpBoolExpr*
2051 PcpGuard::getCondition()
2053 return this->condition;
2056 // Set body to BODY.
2057 void
2058 PcpGuard::setBody(PcpStmt* body)
2060 this->body = body;
2063 // Get body.
2064 PcpStmt*
2065 PcpGuard::getBody()
2067 return this->body;
2070 // Create guard with given CONDITION and BODY.
2071 PcpGuard::PcpGuard(PcpBoolExpr* condition, PcpStmt* body)
2073 initialize();
2074 this->setCondition(condition);
2075 this->setBody(body);
2078 void
2079 PcpGuard::accept(PcpVisitor* visitor)
2081 visitor->visit(this);
2084 // PCP Loop
2086 // Return true if this is a loop.
2087 bool PcpLoop::isLoop()
2089 return true;
2092 // Cast this to a loop.
2093 PcpLoop* PcpLoop::toLoop()
2095 return this;
2098 // Set iv to IV.
2099 void
2100 PcpLoop::setIv(PcpIv* iv)
2102 this->iv = iv;
2105 // Get iv.
2106 PcpIv*
2107 PcpLoop::getIv()
2109 return this->iv;
2112 // Set start to START.
2113 void
2114 PcpLoop::setStart(PcpExpr* start)
2116 this->start = start;
2119 // Get start.
2120 PcpExpr*
2121 PcpLoop::getStart()
2123 return this->start;
2126 // Set condition to CONDITION.
2127 void
2128 PcpLoop::setCondition(PcpBoolExpr* condition)
2130 this->condition = condition;
2133 // Get condition.
2134 PcpBoolExpr*
2135 PcpLoop::getCondition()
2137 return this->condition;
2140 // Set stride to STRIDE.
2141 void
2142 PcpLoop::setStride(PcpConstant* stride)
2144 this->stride = stride;
2147 // Get stride.
2148 PcpConstant*
2149 PcpLoop::getStride()
2151 return this->stride;
2154 // Set body to BODY.
2155 void
2156 PcpLoop::setBody(PcpStmt* body)
2158 this->body = body;
2161 // Get body.
2162 PcpStmt*
2163 PcpLoop::getBody()
2165 return this->body;
2168 // Create loop as loop(IV, START, CONDITION, STRIDE) { BODY }.
2169 PcpLoop::PcpLoop(PcpIv* iv, PcpExpr* start, PcpBoolExpr* condition,
2170 PcpConstant* stride, PcpStmt* body)
2172 initialize();
2173 this->setIv(iv);
2174 this->setStart(start);
2175 this->setCondition(condition);
2176 this->setStride(stride);
2177 this->setBody(body);
2180 void
2181 PcpLoop::accept(PcpVisitor* visitor)
2183 visitor->visit(this);
2186 // PCP Scop
2188 // Return true if this is a scop.
2189 bool PcpScop::isScop()
2191 return true;
2194 // Cast this to a scop.
2195 PcpScop* PcpScop::toScop()
2197 return this;
2200 // Get numer of variables.
2202 PcpScop::getNumVariables()
2204 return this->getVariables()->getSize();
2207 // Set variables to VARIABLES.
2208 void
2209 PcpScop::setVariables(PcpArray<PcpVariable*>* variables)
2211 this->variables = variables;
2214 // Get variables.
2215 PcpArray<PcpVariable*>*
2216 PcpScop::getVariables()
2218 return this->variables;
2221 // Get variable with given INDEX.
2222 PcpVariable*
2223 PcpScop::getVariable(int index)
2225 return this->getVariables()->get(index);
2228 // Get number of paramters.
2230 PcpScop::getNumParameters()
2232 return this->getParameters()->getSize();
2235 // Set paramters to PARAMTERS.
2236 void
2237 PcpScop::setParameters(PcpArray<PcpParameter*>* parameters)
2239 this->parameters = parameters;
2242 // Get parameters.
2243 PcpArray<PcpParameter*>*
2244 PcpScop::getParameters()
2246 return this->parameters;
2249 // Get parameter with given INDEX.
2250 PcpParameter*
2251 PcpScop::getParameter(int index)
2253 return this->getParameters()->get(index);
2256 // Set body to BODY.
2257 void
2258 PcpScop::setBody(PcpStmt* body)
2260 this->body = body;
2263 // Get body.
2264 PcpStmt*
2265 PcpScop::getBody()
2267 return this->body;
2270 PcpIterator<PcpVariable*>*
2271 PcpScop::getVariablesIterator()
2273 return this->getVariables()->getIterator();
2276 PcpIterator<PcpParameter*>*
2277 PcpScop::getParametersIterator()
2279 return this->getParameters()->getIterator();
2283 // Create new scop given VARIABLES, PARAMETERS and BODY.
2284 PcpScop::PcpScop(PcpArray<PcpVariable*>* variables,
2285 PcpArray<PcpParameter*>* parameters,
2286 PcpStmt* body)
2288 initialize();
2289 this->setVariables(variables);
2290 this->setParameters(parameters);
2291 this->setBody(body);
2294 void
2295 PcpScop::accept(PcpVisitor* visitor)
2297 visitor->visit(this);
2300 // Set varaibles to VARAIBLES.
2301 void
2302 PcpScopBuilder::setVariables(PcpDynamicArray<PcpVariable*>* variables)
2304 this->variables = variables;
2307 // Get variables.
2308 PcpDynamicArray<PcpVariable*>*
2309 PcpScopBuilder::getVariables()
2311 return this->variables;
2314 // Set parameters to PARAMETERS.
2315 void
2316 PcpScopBuilder::setParameters(PcpDynamicArray<PcpParameter*>* parameters)
2318 this->parameters = parameters;
2321 // Get parameters.
2322 PcpDynamicArray<PcpParameter*>*
2323 PcpScopBuilder::getParameters()
2325 return this->parameters;
2328 // Return true if VARIABLE already exists in the variables array.
2329 bool
2330 PcpScopBuilder::containsVariable(PcpVariable* variable)
2332 PcpDynamicArray<PcpVariable*>* variables = this->getVariables();
2333 PcpIterator<PcpVariable*>* iter;
2334 bool result = false;
2335 for(iter = variables->getIterator(); iter->hasNext(); iter->next())
2337 if(variable == iter->get())
2338 result = true;
2340 delete iter;
2341 return result;
2344 // Add VARIABLE.
2345 void
2346 PcpScopBuilder::addVariable(PcpVariable* variable)
2348 if(!this->containsVariable(variable))
2349 this->getVariables()->add(variable);
2352 // Add PARAMETER.
2353 void
2354 PcpScopBuilder::addParameter(PcpParameter* parameter)
2356 this->getParameters()->add(parameter);
2359 // Set body to BODY.
2360 void
2361 PcpScopBuilder::setBody(PcpStmt* body)
2363 this->body = body;
2366 // Get body.
2367 PcpStmt*
2368 PcpScopBuilder::getBody()
2370 return this->body;
2373 // Create new scop builder.
2374 PcpScopBuilder::PcpScopBuilder()
2376 this->setVariables(new PcpDynamicArray<PcpVariable*>(5));
2377 this->setParameters(new PcpDynamicArray<PcpParameter*>(5));
2378 this->setBody(NULL);
2381 // Create new scop.
2382 PcpScop*
2383 PcpScopBuilder::createScop()
2385 PcpScop* scop = new PcpScop(this->getVariables(),
2386 this->getParameters(),
2387 this->getBody());
2388 return scop;