-Function::Function(const MethodType *Ty, bool isInternal,
- const std::string &name)
- : GlobalValue(PointerType::get(Ty), Value::MethodVal, isInternal, name),
- SymTabValue(this), BasicBlocks(this), ArgumentList(this, this) {
- assert(::isa<MethodType>(Ty) && "Method signature must be of method type!");
+ if (Par)
+ Par->getArgumentList().push_back(this);
+}
+
+
+// Specialize setName to take care of symbol table majik
+void Argument::setName(const std::string &name, SymbolTable *ST) {
+ Function *P;
+ assert((ST == 0 || (!getParent() || ST == getParent()->getSymbolTable())) &&
+ "Invalid symtab argument!");
+ if ((P = getParent()) && hasName()) P->getSymbolTable()->remove(this);
+ Value::setName(name);
+ if (P && hasName()) P->getSymbolTable()->insert(this);
+}
+
+void Argument::setParent(Function *parent) {
+ if (getParent())
+ LeakDetector::addGarbageObject(this);
+ Parent = parent;
+ if (getParent())
+ LeakDetector::removeGarbageObject(this);
+}
+
+
+//===----------------------------------------------------------------------===//
+// Function Implementation
+//===----------------------------------------------------------------------===//
+
+Function::Function(const FunctionType *Ty, bool isInternal,
+ const std::string &name, Module *ParentModule)
+ : GlobalValue(PointerType::get(Ty), Value::FunctionVal, isInternal, name) {
+ BasicBlocks.setItemParent(this);
+ BasicBlocks.setParent(this);
+ ArgumentList.setItemParent(this);
+ ArgumentList.setParent(this);
+ ParentSymTab = SymTab = 0;
+
+ // Make sure that we get added to a function
+ LeakDetector::addGarbageObject(this);
+
+ if (ParentModule)
+ ParentModule->getFunctionList().push_back(this);