home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 20 / AACD20.BIN / AACD / Programming / Jikes / Source / src / depend.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-24  |  3.8 KB  |  153 lines

  1. // $Id: depend.h,v 1.11 2001/01/05 09:13:20 mdejong Exp $
  2. //
  3. // This software is subject to the terms of the IBM Jikes Compiler
  4. // License Agreement available at the following URL:
  5. // http://www.ibm.com/research/jikes.
  6. // Copyright (C) 1996, 1998, International Business Machines Corporation
  7. // and others.  All Rights Reserved.
  8. // You must accept the terms of that agreement to use this software.
  9. //
  10. #ifndef depend_INCLUDED
  11. #define depend_INCLUDED
  12.  
  13. #include "platform.h"
  14. // Also included in platform.h but that might change
  15. //#include "tuple.h"
  16.  
  17. #ifdef    HAVE_JIKES_NAMESPACE
  18. namespace Jikes {    // Open namespace Jikes block
  19. #endif
  20.  
  21. class Semantic;
  22. class TypeSymbol;
  23. class FileSymbol;
  24. class AstClassBody;
  25. class AstConstructorDeclaration;
  26. class SymbolSet;
  27. class Control;
  28.  
  29. class CycleChecker
  30. {
  31. public:
  32.     enum { OMEGA = -1, CYCLE_INFINITY = INT_MAX };
  33.  
  34.     inline int Min(int x, int y) { return (x < y ? x : y); }
  35. };
  36.  
  37. class TypeCycleChecker : public CycleChecker
  38. {
  39. public:
  40.  
  41.     TypeCycleChecker(Tuple<TypeSymbol *> &type_list_) : type_list(type_list_)
  42.     {}
  43.     void PartialOrder(Tuple<Semantic *> &, int);
  44.     void PartialOrder(SymbolSet &);
  45.  
  46. private:
  47.     class Stack
  48.     {
  49.     public:
  50.         void Push(TypeSymbol *type) { info.Next() = type; }
  51.         void Pop()                  { if (info.Length() > 0) info.Reset(info.Length() - 1); }
  52.         int Size()                  { return info.Length(); }
  53.         TypeSymbol *Top()           { return (TypeSymbol *) (info.Length() > 0 ? info[info.Length() - 1] : NULL); }
  54.     private:
  55.         Tuple<TypeSymbol *> info;
  56.     } stack;
  57.  
  58.     Tuple<TypeSymbol *> &type_list;
  59.  
  60.     void ProcessSubtypes(TypeSymbol *);
  61.     void ReverseTypeList();
  62. };
  63.  
  64.  
  65. class ConstructorCycleChecker : public CycleChecker
  66. {
  67. public:
  68.  
  69.     ConstructorCycleChecker(AstClassBody *);
  70.  
  71. private:
  72.     class Stack
  73.     {
  74.     public:
  75.         void Push(AstConstructorDeclaration *constructor) { info.Next() = constructor; }
  76.         void Pop()                                        { if (info.Length() > 0) info.Reset(info.Length() - 1); }
  77.         int Size()                                        { return info.Length(); }
  78.         AstConstructorDeclaration *Top()
  79.            { return (AstConstructorDeclaration *) (info.Length() > 0 ? info[info.Length() - 1] : NULL);}
  80.     private:
  81.         Tuple<AstConstructorDeclaration *> info;
  82.     } stack;
  83.  
  84.     void CheckConstructorCycles(AstConstructorDeclaration *);
  85. };
  86.  
  87.  
  88. class TypeDependenceChecker : public CycleChecker
  89. {
  90. public:
  91.     TypeDependenceChecker(Control *control_, SymbolSet &file_set_, Tuple<TypeSymbol *> &type_trash_bin_)
  92.         : file_set(file_set_),
  93.           control(control_),
  94.           type_trash_bin(type_trash_bin_)
  95.     {}
  96.  
  97.     ~TypeDependenceChecker() {}
  98.  
  99.     void PartialOrder();
  100.     void OutputDependences();
  101.  
  102.     Tuple<TypeSymbol *> &TypeList() { return type_list; }
  103.  
  104.     SymbolSet &file_set;
  105.  
  106. private:
  107.     Control *control;
  108.     Tuple<TypeSymbol *> &type_trash_bin;
  109.  
  110.     class Stack
  111.     {
  112.     public:
  113.         void Push(TypeSymbol *type) { info.Next() = type; }
  114.         void Pop()                  { if (info.Length() > 0) info.Reset(info.Length() - 1); }
  115.         int Size()                  { return info.Length(); }
  116.         TypeSymbol *Top()           { return (TypeSymbol *) (info.Length() > 0 ? info[info.Length() - 1] : NULL); }
  117.     private:
  118.         Tuple<TypeSymbol *> info;
  119.     } stack;
  120.  
  121.     void OutputMake(FILE *, char *, Tuple<FileSymbol *> &);
  122.     void OutputMake(FileSymbol *);
  123.  
  124.     Tuple<TypeSymbol *> type_list;
  125.  
  126.     void ProcessType(TypeSymbol *);
  127. };
  128.  
  129.  
  130. class TopologicalSort
  131. {
  132. public:
  133.     TopologicalSort(SymbolSet &, Tuple<TypeSymbol *> &);
  134.     ~TopologicalSort();
  135.  
  136.     void Sort();
  137.  
  138. private:
  139.     void Process(TypeSymbol *);
  140.  
  141.     SymbolSet *pending;
  142.  
  143.     SymbolSet &type_collection;
  144.     Tuple<TypeSymbol *> &type_list;
  145. };
  146.  
  147. #ifdef    HAVE_JIKES_NAMESPACE
  148. }            // Close namespace Jikes block
  149. #endif
  150.  
  151. #endif /* cycle_INCLUDED */
  152.  
  153.