[llvm-commits] CVS: llvm/lib/AsmParser/llvmAsmParser.y

Chris Lattner lattner at cs.uiuc.edu
Tue Oct 15 16:42:00 PDT 2002


Changes in directory llvm/lib/AsmParser:

llvmAsmParser.y updated: 1.97 -> 1.98

---
Log message:

  - Fix bug: Assembler/2002-10-15-NameClash.ll
  - Clean up code a bit, s/Method/Function/


---
Diffs of the changes:

Index: llvm/lib/AsmParser/llvmAsmParser.y
diff -u llvm/lib/AsmParser/llvmAsmParser.y:1.97 llvm/lib/AsmParser/llvmAsmParser.y:1.98
--- llvm/lib/AsmParser/llvmAsmParser.y:1.97	Sun Oct 13 22:28:42 2002
+++ llvm/lib/AsmParser/llvmAsmParser.y	Tue Oct 15 16:41:14 2002
@@ -1210,50 +1210,50 @@
   string FunctionName($3);
   
   vector<const Type*> ParamTypeList;
-  if ($5)
+  if ($5) {   // If there are arguments...
     for (vector<pair<PATypeHolder*,char*> >::iterator I = $5->begin();
          I != $5->end(); ++I)
       ParamTypeList.push_back(I->first->get());
+  }
 
   bool isVarArg = ParamTypeList.size() && ParamTypeList.back() == Type::VoidTy;
   if (isVarArg) ParamTypeList.pop_back();
 
-  const FunctionType *MT = FunctionType::get(*$2, ParamTypeList, isVarArg);
-  const PointerType *PMT = PointerType::get(MT);
+  const FunctionType *FT = FunctionType::get(*$2, ParamTypeList, isVarArg);
+  const PointerType *PFT = PointerType::get(FT);
   delete $2;
 
-  Function *M = 0;
-  if (SymbolTable *ST = CurModule.CurrentModule->getSymbolTable()) {
-    // Is the function already in symtab?
-    if (Value *V = ST->lookup(PMT, FunctionName)) {
-      M = cast<Function>(V);
-
-      // Yes it is.  If this is the case, either we need to be a forward decl,
-      // or it needs to be.
-      if (!CurMeth.isDeclare && !M->isExternal())
-	ThrowException("Redefinition of function '" + FunctionName + "'!");
-
-      // Make sure that we keep track of the internal marker, even if there was
-      // a previous "declare".
-      if ($1)
-        M->setInternalLinkage(true);
-
-      // If we found a preexisting function prototype, remove it from the
-      // module, so that we don't get spurious conflicts with global & local
-      // variables.
-      //
-      CurModule.CurrentModule->getFunctionList().remove(M);
-    }
-  }
-
-  if (M == 0) {  // Not already defined?
-    M = new Function(MT, $1, FunctionName);
-    InsertValue(M, CurModule.Values);
-    CurModule.DeclareNewGlobalValue(M, ValID::create($3));
+  Function *Fn = 0;
+  // Is the function already in symtab?
+  if ((Fn = CurModule.CurrentModule->getFunction(FunctionName, FT))) {
+    // Yes it is.  If this is the case, either we need to be a forward decl,
+    // or it needs to be.
+    if (!CurMeth.isDeclare && !Fn->isExternal())
+      ThrowException("Redefinition of function '" + FunctionName + "'!");
+    
+    // Make sure that we keep track of the internal marker, even if there was
+    // a previous "declare".
+    if ($1)
+      Fn->setInternalLinkage(true);
+
+    // If we found a preexisting function prototype, remove it from the
+    // module, so that we don't get spurious conflicts with global & local
+    // variables.
+    //
+    CurModule.CurrentModule->getFunctionList().remove(Fn);
+
+    // Make sure to strip off any argument names so we can't get conflicts...
+    for (Function::aiterator AI = Fn->abegin(), AE = Fn->aend(); AI != AE; ++AI)
+      AI->setName("");
+
+  } else  {  // Not already defined?
+    Fn = new Function(FT, $1, FunctionName);
+    InsertValue(Fn, CurModule.Values);
+    CurModule.DeclareNewGlobalValue(Fn, ValID::create($3));
   }
   free($3);  // Free strdup'd memory!
 
-  CurMeth.FunctionStart(M);
+  CurMeth.FunctionStart(Fn);
 
   // Add all of the arguments we parsed to the function...
   if ($5) {                     // Is null if empty...
@@ -1263,7 +1263,7 @@
       delete $5->back().first;
       $5->pop_back();  // Delete the last entry
     }
-    Function::aiterator ArgIt = M->abegin();
+    Function::aiterator ArgIt = Fn->abegin();
     for (vector<pair<PATypeHolder*, char*> >::iterator I = $5->begin();
          I != $5->end(); ++I, ++ArgIt) {
       delete I->first;                          // Delete the typeholder...
@@ -1411,11 +1411,11 @@
   }
   | INVOKE TypesV ValueRef '(' ValueRefListE ')' TO ResolvedVal 
     EXCEPT ResolvedVal {
-    const PointerType *PMTy;
+    const PointerType *PFTy;
     const FunctionType *Ty;
 
-    if (!(PMTy = dyn_cast<PointerType>($2->get())) ||
-        !(Ty = dyn_cast<FunctionType>(PMTy->getElementType()))) {
+    if (!(PFTy = dyn_cast<PointerType>($2->get())) ||
+        !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
       // Pull out the types of all of the arguments...
       vector<const Type*> ParamTypes;
       if ($5) {
@@ -1427,11 +1427,11 @@
       if (isVarArg) ParamTypes.pop_back();
 
       Ty = FunctionType::get($2->get(), ParamTypes, isVarArg);
-      PMTy = PointerType::get(Ty);
+      PFTy = PointerType::get(Ty);
     }
     delete $2;
 
-    Value *V = getVal(PMTy, $3);   // Get the function we're calling...
+    Value *V = getVal(PFTy, $3);   // Get the function we're calling...
 
     BasicBlock *Normal = dyn_cast<BasicBlock>($8);
     BasicBlock *Except = dyn_cast<BasicBlock>($10);
@@ -1570,11 +1570,11 @@
     delete $2;  // Free the list...
   } 
   | CALL TypesV ValueRef '(' ValueRefListE ')' {
-    const PointerType *PMTy;
+    const PointerType *PFTy;
     const FunctionType *Ty;
 
-    if (!(PMTy = dyn_cast<PointerType>($2->get())) ||
-        !(Ty = dyn_cast<FunctionType>(PMTy->getElementType()))) {
+    if (!(PFTy = dyn_cast<PointerType>($2->get())) ||
+        !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
       // Pull out the types of all of the arguments...
       vector<const Type*> ParamTypes;
       if ($5) {
@@ -1586,11 +1586,11 @@
       if (isVarArg) ParamTypes.pop_back();
 
       Ty = FunctionType::get($2->get(), ParamTypes, isVarArg);
-      PMTy = PointerType::get(Ty);
+      PFTy = PointerType::get(Ty);
     }
     delete $2;
 
-    Value *V = getVal(PMTy, $3);   // Get the function we're calling...
+    Value *V = getVal(PFTy, $3);   // Get the function we're calling...
 
     // Create the call node...
     if (!$5) {                                   // Has no arguments?





More information about the llvm-commits mailing list