1 // $Id: depend.h,v 1.15 2002/06/18 04:06:55 cabbey Exp $ -*- c++ -*-
2 //
3 // This software is subject to the terms of the IBM Jikes Compiler
4 // License Agreement available at the following URL:
5 // http://ibm.com/developerworks/opensource/jikes.
6 // Copyright (C) 1996, 1998, 1999, 2000, 2001 International Business
7 // Machines Corporation and others.  All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 //
10 
11 #ifndef depend_INCLUDED
12 #define depend_INCLUDED
13 
14 #include "platform.h"
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 template <typename T>
30 class CycleChecker
31 {
32 public:
33     enum { OMEGA = -1, CYCLE_INFINITY = INT_MAX };
34 
Min(int x,int y)35     inline int Min(int x, int y) { return (x < y ? x : y); }
36 
37 protected:
38     class Stack
39     {
40     public:
Push(T * t)41         void Push(T *t) { info.Next() = t; }
Pop()42         void Pop() { if (info.Length() > 0) info.Reset(info.Length() - 1); }
Size()43         int Size() { return info.Length(); }
Top()44         T *Top()
45         {
46             return (T *) (info.Length() > 0 ? info[info.Length() - 1] : NULL);
47         }
48     private:
49         Tuple<T *> info;
50     } stack;
51 };
52 
53 class TypeCycleChecker : public CycleChecker<TypeSymbol>
54 {
55 public:
56 
TypeCycleChecker(Tuple<TypeSymbol * > & type_list_)57     TypeCycleChecker(Tuple<TypeSymbol *> &type_list_) : type_list(type_list_)
58     {}
59     void PartialOrder(Tuple<Semantic *> &, int);
60     void PartialOrder(SymbolSet &);
61 
62 private:
63     Tuple<TypeSymbol *> &type_list;
64 
65     void ProcessSubtypes(TypeSymbol *);
66     void ReverseTypeList();
67 };
68 
69 
70 class ConstructorCycleChecker : public CycleChecker<AstConstructorDeclaration>
71 {
72 public:
73     ConstructorCycleChecker(AstClassBody *);
74 
75 private:
76     void CheckConstructorCycles(AstConstructorDeclaration *);
77 };
78 
79 
80 class TypeDependenceChecker : public CycleChecker<TypeSymbol>
81 {
82 public:
TypeDependenceChecker(Control * control_,SymbolSet & file_set_,Tuple<TypeSymbol * > & type_trash_bin_)83     TypeDependenceChecker(Control *control_,
84                           SymbolSet &file_set_,
85                           Tuple<TypeSymbol *> &type_trash_bin_) : file_set(file_set_),
86                                                                   control(control_),
87                                                                   type_trash_bin(type_trash_bin_)
88     {}
89 
~TypeDependenceChecker()90     ~TypeDependenceChecker() {}
91 
92     void PartialOrder();
93     void OutputDependences();
94 
TypeList()95     Tuple<TypeSymbol *> &TypeList() { return type_list; }
96 
97     SymbolSet &file_set;
98 
99 private:
100     Control *control;
101     Tuple<TypeSymbol *> &type_trash_bin;
102 
103     void OutputMake(FILE *, char *, Tuple<FileSymbol *> &);
104     void OutputMake(FileSymbol *);
105 
106     Tuple<TypeSymbol *> type_list;
107 
108     void ProcessType(TypeSymbol *);
109 };
110 
111 
112 class TopologicalSort
113 {
114 public:
115     TopologicalSort(SymbolSet &, Tuple<TypeSymbol *> &);
116     ~TopologicalSort();
117 
118     void Sort();
119 
120 private:
121     void Process(TypeSymbol *);
122 
123     SymbolSet *pending;
124 
125     SymbolSet &type_collection;
126     Tuple<TypeSymbol *> &type_list;
127 };
128 
129 #ifdef HAVE_JIKES_NAMESPACE
130 } // Close namespace Jikes block
131 #endif
132 
133 #endif // depend_INCLUDED
134 
135