+
+// 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);
+ SymTab = new SymbolTable();
+
+ // Create the arguments vector, all arguments start out unnamed.
+ for (unsigned i = 0, e = Ty->getNumParams(); i != e; ++i) {
+ assert(Ty->getParamType(i) != Type::VoidTy &&
+ "Cannot have void typed arguments!");
+ ArgumentList.push_back(new Argument(Ty->getParamType(i)));
+ }
+
+ // Make sure that we get added to a function
+ LeakDetector::addGarbageObject(this);
+
+ if (ParentModule)
+ ParentModule->getFunctionList().push_back(this);
+}
+
+Function::~Function() {