Dependency solving

"Piotr Wyderski" <piotr.wyderski@wp.pl>
29 Apr 2004 11:59:25 -0400

          From comp.compilers

Related articles
Dependency solving piotr.wyderski@wp.pl (Piotr Wyderski) (2004-04-29)
Re: Dependency solving wyrmwif@tsoft.com (SM Ryan) (2004-05-02)
| List of all articles for this month |

From: "Piotr Wyderski" <piotr.wyderski@wp.pl>
Newsgroups: comp.compilers
Date: 29 Apr 2004 11:59:25 -0400
Organization: Faculty of Computer Science, University of Wroclaw
Keywords: OOP, analysis, question
Posted-Date: 29 Apr 2004 11:59:25 EDT

How are cyclic dependencies solved in object-oriented languages?
Say, we have a class (in a C++-like language):


        class T {


                public:


                        T clone() {


                                T p();
                                return p;
                        }
        };


To solve dependencied of the class T, which depends on
the method clone(), the type checking mechanism must
solve dependencies of clone(), which depends on T.
A simple, recursive solver, like this pseudocode:


solve_type(t)
        if (t == class)
                solve_class(c)
end


solve_class(c)
        for all m in methods
                solve_method(m)
end


solve_method(m)
        solve_type(m.return_type)
        solve_body()
end


will loop forever. Node marking (to detect a cycle)
doesn't help much, it only allows us to break the
cycle and report an error. However most programming
languages do not have problems with cycles and they
gently solve such dependencies. So, how does the
algorithm work?


        Best regards
        Piotr Wyderski


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.