Fixed one dead loop issue in the autogenlib.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2240 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
zliu3
2007-01-12 08:50:20 +00:00
parent 34dca9d54a
commit e360ea4d73

View File

@ -1,15 +1,15 @@
/**@file /**@file
AutogenLibOrder class. AutogenLibOrder class.
This class is to reorder library instance sequence according to library This class is to reorder library instance sequence according to library
dependence. dependence.
Copyright (c) 2006, Intel Corporation Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@ -62,12 +62,12 @@ public class AutogenLibOrder {
/// String[1] is libraryConstructor name, String[2] is libDestructor name. /// String[1] is libraryConstructor name, String[2] is libDestructor name.
/// ///
private ModuleIdentification[] libInstanceList = null; private ModuleIdentification[] libInstanceList = null;
/** /**
Constructor function Constructor function
This function mainly initialize some member variable. This function mainly initialize some member variable.
@param libraryList List of the library instance. @param libraryList List of the library instance.
@throws Exception @throws Exception
**/ **/
@ -81,12 +81,12 @@ public class AutogenLibOrder {
libInstance = libraryList[i]; libInstance = libraryList[i];
// //
// Fetch the constructor & destructor. // Fetch the constructor & destructor.
// //
Map<String, XmlObject> libDoc = GlobalData.getDoc(libInstance, arch); Map<String, XmlObject> libDoc = GlobalData.getDoc(libInstance, arch);
SurfaceAreaQuery saq = new SurfaceAreaQuery(libDoc); SurfaceAreaQuery saq = new SurfaceAreaQuery(libDoc);
libInstance.setConstructor(saq.getLibConstructorName()); libInstance.setConstructor(saq.getLibConstructorName());
libInstance.setDestructor(saq.getLibDestructorName()); libInstance.setDestructor(saq.getLibDestructorName());
// //
// Create library class consume database. // Create library class consume database.
// //
@ -122,8 +122,8 @@ public class AutogenLibOrder {
} }
// //
// Create a consumed-by database // Create a consumed-by database
// //
for (Iterator it = libClassProducer.keySet().iterator(); it.hasNext();) { for (Iterator it = libClassProducer.keySet().iterator(); it.hasNext();) {
String className = (String)it.next(); String className = (String)it.next();
libInstance = libClassProducer.get(className); libInstance = libClassProducer.get(className);
@ -145,7 +145,7 @@ public class AutogenLibOrder {
/** /**
orderLibInstance orderLibInstance
This function reorder the library instance according the library class This function reorder the library instance according the library class
dependency, using DAG anaylysis algothim dependency, using DAG anaylysis algothim
@return List which content the ordered library instance. @return List which content the ordered library instance.
@ -156,7 +156,7 @@ public class AutogenLibOrder {
// //
// First, add the library instance without consumers to the Q // First, add the library instance without consumers to the Q
// //
for (int i = 0; i < libInstanceList.length; ++i) { for (int i = 0; i < libInstanceList.length; ++i) {
if (libInstanceConsumedBy.get(libInstanceList[i]).size() == 0) { if (libInstanceConsumedBy.get(libInstanceList[i]).size() == 0) {
noConsumerList.add(libInstanceList[i]); noConsumerList.add(libInstanceList[i]);
@ -174,6 +174,10 @@ public class AutogenLibOrder {
continue; continue;
} }
HashSet<ModuleIdentification> consumedBy = libInstanceConsumedBy.get(m); HashSet<ModuleIdentification> consumedBy = libInstanceConsumedBy.get(m);
if (consumedBy.size() == 0) {
continue;
}
consumedBy.remove(n); consumedBy.remove(n);
if (consumedBy.size() == 0) { if (consumedBy.size() == 0) {
noConsumerList.addLast(m); noConsumerList.addLast(m);
@ -200,10 +204,11 @@ public class AutogenLibOrder {
if (consumer.hasConstructor()) { if (consumer.hasConstructor()) {
continue; continue;
} }
// //
// if there's no constructor in the library instance's consumer, // if there's no constructor in the library instance's consumer,
// remove it from the consumer list // remove it from the consumer list
// //
consumedBy.remove(consumer); consumedBy.remove(consumer);
circularlyConsumed = false; circularlyConsumed = false;
if (consumedBy.size() == 0) { if (consumedBy.size() == 0) {
@ -216,12 +221,16 @@ public class AutogenLibOrder {
break; break;
} }
} }
if (noConsumerList.size() == 0 && !circularlyConsumed) {
break;
}
} }
} }
// //
// Append the remaining library instance to the end of sorted list // Append the remaining library instance to the end of sorted list
// //
for (int i = 0; i < libInstanceList.length; ++i) { for (int i = 0; i < libInstanceList.length; ++i) {
if (libInstanceConsumedBy.get(libInstanceList[i]).size() > 0 && libInstanceList[i].hasConstructor()) { if (libInstanceConsumedBy.get(libInstanceList[i]).size() > 0 && libInstanceList[i].hasConstructor()) {
EdkLog.log(EdkLog.EDK_ERROR, libInstanceList[i].getName() EdkLog.log(EdkLog.EDK_ERROR, libInstanceList[i].getName()