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

LLVM llvm at cs.uiuc.edu
Sun May 16 19:08:01 PDT 2004


Changes in directory llvm/lib/AsmParser:

llvmAsmParser.y updated: 1.163 -> 1.163.2.1

---
Log message:

Changes resulting from Type not being a Value any more. Had to create a
new "setTypeName" function to handle types separately from Values. Made the
parser conform its use of SymbolTable to that class's new interface. None 
of the productions changed significantly.


---
Diffs of the changes:  (+66 -22)

Index: llvm/lib/AsmParser/llvmAsmParser.y
diff -u llvm/lib/AsmParser/llvmAsmParser.y:1.163 llvm/lib/AsmParser/llvmAsmParser.y:1.163.2.1
--- llvm/lib/AsmParser/llvmAsmParser.y:1.163	Sat Apr 17 18:49:15 2004
+++ llvm/lib/AsmParser/llvmAsmParser.y	Sun May 16 19:08:47 2004
@@ -236,10 +236,10 @@
   case ValID::NameVal: {                // Is it a named definition?
     std::string Name(D.Name);
     SymbolTable *SymTab = 0;
-    Value *N = 0;
+    Type *N = 0;
     if (inFunctionScope()) {
       SymTab = &CurFun.CurrentFunction->getSymbolTable();
-      N = SymTab->lookup(Type::TypeTy, Name);
+      N = SymTab->lookupType(Name);
     }
 
     if (N == 0) {
@@ -247,12 +247,12 @@
       // hasn't been added to the module...
       //
       SymTab = &CurModule.CurrentModule->getSymbolTable();
-      N = SymTab->lookup(Type::TypeTy, Name);
+      N = SymTab->lookupType(Name);
       if (N == 0) break;
     }
 
     D.destroy();  // Free old strdup'd memory...
-    return cast<Type>(N);
+    return N;
   }
   default:
     ThrowException("Internal parser error: Invalid symbol type reference!");
@@ -377,7 +377,6 @@
 // real thing.
 //
 static Value *getVal(const Type *Ty, const ValID &D) {
-  assert(Ty != Type::TypeTy && "Should use getTypeVal for types!");
 
   // See if the value has already been defined...
   Value *V = getValNonImprovising(Ty, D);
@@ -517,23 +516,9 @@
 
   Value *Existing = ST.lookup(V->getType(), Name);
   if (Existing) {    // Inserting a name that is already defined???
-    // There is only one case where this is allowed: when we are refining an
-    // opaque type.  In this case, Existing will be an opaque type.
-    if (const Type *Ty = dyn_cast<Type>(Existing)) {
-      if (const OpaqueType *OpTy = dyn_cast<OpaqueType>(Ty)) {
-	// We ARE replacing an opaque type!
-	((OpaqueType*)OpTy)->refineAbstractTypeTo(cast<Type>(V));
-	return true;
-      }
-    }
 
-    // Otherwise, we are a simple redefinition of a value, check to see if it
-    // is defined the same as the old one...
-    if (const Type *Ty = dyn_cast<Type>(Existing)) {
-      if (Ty == cast<Type>(V)) return true;  // Yes, it's equal.
-      // std::cerr << "Type: " << Ty->getDescription() << " != "
-      //      << cast<Type>(V)->getDescription() << "!\n";
-    } else if (const Constant *C = dyn_cast<Constant>(Existing)) {
+    // Check for legal redefinitions of constants and global variables.
+    if (const Constant *C = dyn_cast<Constant>(Existing)) {
       if (C == V) return true;      // Constants are equal to themselves
     } else if (GlobalVariable *EGV = dyn_cast<GlobalVariable>(Existing)) {
       // We are allowed to redefine a global variable in two circumstances:
@@ -586,6 +571,65 @@
 }
 
 
+static bool setTypeName(Type *T, char *NameStr) {
+  if (NameStr == 0) return false;
+  
+  std::string Name(NameStr);      // Copy string
+  free(NameStr);                  // Free old string
+
+  if (T->getType() == Type::VoidTy) 
+    ThrowException("Can't assign name '" + Name + 
+		   "' to a null valued instruction!");
+
+  SymbolTable &ST = inFunctionScope() ? 
+    CurFun.CurrentFunction->getSymbolTable() : 
+    CurModule.CurrentModule->getSymbolTable();
+
+  Type *Existing = ST.lookupType(Name);
+  if (Existing) {    // Inserting a name that is already defined???
+    // There is only one case where this is allowed: when we are refining an
+    // opaque type.  In this case, Existing will be an opaque type.
+    if ( Existing ) {
+      if (const OpaqueType *OpTy = dyn_cast<OpaqueType>(T)) {
+	// We ARE replacing an opaque type!
+	((OpaqueType*)OpTy)->refineAbstractTypeTo(T);
+	return true;
+      }
+    }
+
+    // Otherwise, we are a simple redefinition of a value, check to see if it
+    // is defined the same as the old one...
+    if ( Existing ) {
+      if (Existing == T) return true;  // Yes, it's equal.
+      // std::cerr << "Type: " << Ty->getDescription() << " != "
+      //      << cast<Type>(V)->getDescription() << "!\n";
+    } 
+
+    ThrowException("Redefinition of type named '" + Name + "' in the '" +
+		   T->getDescription() + "' type plane!");
+  }
+
+  // If we're in function scope
+  if (inFunctionScope()) {
+    // Look up the symbol in the function's local symboltable
+    Existing = CurFun.LocalSymtab.lookupType(Name);
+
+    // If it already exists
+    if (Existing) {
+      // Bail
+      ThrowException("Redefinition of type named '" + Name + "' in the '" +
+		   T->getDescription() + "' type plane!");
+
+    // otherwise, since it doesn't exist
+    } else {
+      // Insert it.
+      CurFun.LocalSymtab.insert(Name,T);
+    }
+  }
+  return false;
+}
+
+
 //===----------------------------------------------------------------------===//
 // Code for handling upreferences in type names...
 //
@@ -1346,7 +1390,7 @@
     ResolveTypeTo($2, $4->get());
 
     // TODO: FIXME when Type are not const
-    if (!setValueName(const_cast<Type*>($4->get()), $2)) {
+    if (!setTypeName(const_cast<Type*>($4->get()), $2)) {
       // If this is not a redefinition of a type...
       if (!$2) {
         InsertType($4->get(),





More information about the llvm-commits mailing list