Disallow redefinition of built-in functions.

TRAC #21173
Issue=343
Signed-off-by: Daniel Koch
Author: Nicolas Capens

git-svn-id: https://angleproject.googlecode.com/svn/trunk@1206 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/compiler/SymbolTable.h b/src/compiler/SymbolTable.h
index 33616dc..a89499e 100644
--- a/src/compiler/SymbolTable.h
+++ b/src/compiler/SymbolTable.h
@@ -298,6 +298,11 @@
         return symbol;
     }
 
+    TSymbol *findBuiltIn(const TString &name)
+    {
+        return table[0]->find(name);
+    }
+
     TSymbolTableLevel* getGlobalLevel() {
         assert(table.size() >= 2);
         return table[1];
diff --git a/src/compiler/glslang.y b/src/compiler/glslang.y
index ab4aa2c..8224f5a 100644
--- a/src/compiler/glslang.y
+++ b/src/compiler/glslang.y
@@ -2034,6 +2034,15 @@
 function_definition
     : function_prototype {
         TFunction* function = $1.function;
+        
+        const TSymbol *builtIn = context->symbolTable.findBuiltIn(function->getMangledName());
+        
+        if (builtIn)
+        {
+            context->error($1.line, "built-in functions cannot be redefined", function->getName().c_str());
+            context->recover();
+        }
+        
         TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find(function->getMangledName()));
         //
         // Note:  'prevDec' could be 'function' if this is the first time we've seen function
diff --git a/src/compiler/glslang_tab.cpp b/src/compiler/glslang_tab.cpp
index d58536d..f1f55c0 100644
--- a/src/compiler/glslang_tab.cpp
+++ b/src/compiler/glslang_tab.cpp
@@ -4428,6 +4428,15 @@
 
     {
         TFunction* function = (yyvsp[(1) - (1)].interm).function;
+        
+        const TSymbol *builtIn = context->symbolTable.findBuiltIn(function->getMangledName());
+        
+        if (builtIn)
+        {
+            context->error((yyvsp[(1) - (1)].interm).line, "built-in functions cannot be redefined", function->getName().c_str());
+            context->recover();
+        }
+        
         TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find(function->getMangledName()));
         //
         // Note:  'prevDec' could be 'function' if this is the first time we've seen function