add exp hash in MacroSignature to distinguish macro redefinition 79/19379/2
Antoine ELIAS [Wed, 16 Aug 2017 15:17:42 +0000 (17:17 +0200)]
Change-Id: Ia5a8a10f56b139aea6ac587d65fcb4c7b8edfb95

scilab/modules/ast/Makefile.am
scilab/modules/ast/Makefile.in
scilab/modules/ast/ast.vcxproj
scilab/modules/ast/ast.vcxproj.filters
scilab/modules/ast/includes/analysis/data/MacroSignature.hxx
scilab/modules/ast/includes/symbol/context.hxx
scilab/modules/ast/includes/symbol/variables.hxx
scilab/modules/ast/src/cpp/analysis/MacroSignature.cpp [new file with mode: 0644]
scilab/modules/ast/src/cpp/types/macro.cpp

index a4c9765..f99780d 100644 (file)
@@ -172,6 +172,7 @@ src/cpp/analysis/VisitSimpleVar.cpp \
 src/cpp/analysis/VisitDollarVar.cpp \
 src/cpp/analysis/VisitVarDec.cpp \
 src/cpp/analysis/XBlock.cpp \
+src/cpp/analysis/MacroSignature.cpp \
 src/cpp/analysis/check_____dotpower____.cpp \
 src/cpp/analysis/check_rand.cpp \
 src/cpp/analysis/check_____ge____.cpp \
index be3b3eb..1cd22a8 100644 (file)
@@ -306,6 +306,7 @@ am__libsciast_la_SOURCES_DIST = src/c/operations/doublecomplex.c \
        src/cpp/analysis/VisitSimpleVar.cpp \
        src/cpp/analysis/VisitDollarVar.cpp \
        src/cpp/analysis/VisitVarDec.cpp src/cpp/analysis/XBlock.cpp \
+       src/cpp/analysis/MacroSignature.cpp \
        src/cpp/analysis/check_____dotpower____.cpp \
        src/cpp/analysis/check_rand.cpp \
        src/cpp/analysis/check_____ge____.cpp \
@@ -538,6 +539,7 @@ am_libsciast_la_OBJECTS =  \
        src/cpp/analysis/libsciast_la-VisitDollarVar.lo \
        src/cpp/analysis/libsciast_la-VisitVarDec.lo \
        src/cpp/analysis/libsciast_la-XBlock.lo \
+       src/cpp/analysis/libsciast_la-MacroSignature.lo \
        src/cpp/analysis/libsciast_la-check_____dotpower____.lo \
        src/cpp/analysis/libsciast_la-check_rand.lo \
        src/cpp/analysis/libsciast_la-check_____ge____.lo \
@@ -1126,6 +1128,7 @@ libsciast_la_SOURCES = src/c/operations/doublecomplex.c \
        src/cpp/analysis/VisitSimpleVar.cpp \
        src/cpp/analysis/VisitDollarVar.cpp \
        src/cpp/analysis/VisitVarDec.cpp src/cpp/analysis/XBlock.cpp \
+       src/cpp/analysis/MacroSignature.cpp \
        src/cpp/analysis/check_____dotpower____.cpp \
        src/cpp/analysis/check_rand.cpp \
        src/cpp/analysis/check_____ge____.cpp \
@@ -2080,6 +2083,9 @@ src/cpp/analysis/libsciast_la-VisitVarDec.lo:  \
 src/cpp/analysis/libsciast_la-XBlock.lo:  \
        src/cpp/analysis/$(am__dirstamp) \
        src/cpp/analysis/$(DEPDIR)/$(am__dirstamp)
+src/cpp/analysis/libsciast_la-MacroSignature.lo:  \
+       src/cpp/analysis/$(am__dirstamp) \
+       src/cpp/analysis/$(DEPDIR)/$(am__dirstamp)
 src/cpp/analysis/libsciast_la-check_____dotpower____.lo:  \
        src/cpp/analysis/$(am__dirstamp) \
        src/cpp/analysis/$(DEPDIR)/$(am__dirstamp)
@@ -2389,6 +2395,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/analysis/$(DEPDIR)/libsciast_la-LengthAnalyzer.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/analysis/$(DEPDIR)/libsciast_la-LoopBlock.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/analysis/$(DEPDIR)/libsciast_la-MacroDef.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/cpp/analysis/$(DEPDIR)/libsciast_la-MacroSignature.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/analysis/$(DEPDIR)/libsciast_la-MatrixAnalyzer.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/analysis/$(DEPDIR)/libsciast_la-MemInitAnalyzer.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/analysis/$(DEPDIR)/libsciast_la-MultivariateMonomial.Plo@am__quote@
@@ -3723,6 +3730,13 @@ src/cpp/analysis/libsciast_la-XBlock.lo: src/cpp/analysis/XBlock.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciast_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/analysis/libsciast_la-XBlock.lo `test -f 'src/cpp/analysis/XBlock.cpp' || echo '$(srcdir)/'`src/cpp/analysis/XBlock.cpp
 
+src/cpp/analysis/libsciast_la-MacroSignature.lo: src/cpp/analysis/MacroSignature.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciast_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/analysis/libsciast_la-MacroSignature.lo -MD -MP -MF src/cpp/analysis/$(DEPDIR)/libsciast_la-MacroSignature.Tpo -c -o src/cpp/analysis/libsciast_la-MacroSignature.lo `test -f 'src/cpp/analysis/MacroSignature.cpp' || echo '$(srcdir)/'`src/cpp/analysis/MacroSignature.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/cpp/analysis/$(DEPDIR)/libsciast_la-MacroSignature.Tpo src/cpp/analysis/$(DEPDIR)/libsciast_la-MacroSignature.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='src/cpp/analysis/MacroSignature.cpp' object='src/cpp/analysis/libsciast_la-MacroSignature.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciast_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/analysis/libsciast_la-MacroSignature.lo `test -f 'src/cpp/analysis/MacroSignature.cpp' || echo '$(srcdir)/'`src/cpp/analysis/MacroSignature.cpp
+
 src/cpp/analysis/libsciast_la-check_____dotpower____.lo: src/cpp/analysis/check_____dotpower____.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciast_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/analysis/libsciast_la-check_____dotpower____.lo -MD -MP -MF src/cpp/analysis/$(DEPDIR)/libsciast_la-check_____dotpower____.Tpo -c -o src/cpp/analysis/libsciast_la-check_____dotpower____.lo `test -f 'src/cpp/analysis/check_____dotpower____.cpp' || echo '$(srcdir)/'`src/cpp/analysis/check_____dotpower____.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/cpp/analysis/$(DEPDIR)/libsciast_la-check_____dotpower____.Tpo src/cpp/analysis/$(DEPDIR)/libsciast_la-check_____dotpower____.Plo
index da9c11c..bcc91ef 100644 (file)
@@ -626,6 +626,7 @@ lib /DEF:"$(ProjectDir)functions_manager_import.def" /SUBSYSTEM:WINDOWS /MACHINE
     <ClCompile Include="src\cpp\analysis\LengthAnalyzer.cpp" />
     <ClCompile Include="src\cpp\analysis\LoopBlock.cpp" />
     <ClCompile Include="src\cpp\analysis\MacroDef.cpp" />
+    <ClCompile Include="src\cpp\analysis\MacroSignature.cpp" />
     <ClCompile Include="src\cpp\analysis\MatrixAnalyzer.cpp" />
     <ClCompile Include="src\cpp\analysis\MemInitAnalyzer.cpp" />
     <ClCompile Include="src\cpp\analysis\MultivariateMonomial.cpp" />
index af27295..21f0521 100644 (file)
     <ClCompile Include="src\cpp\ast\FBlockListener.cpp">
       <Filter>Source Files\ast</Filter>
     </ClCompile>
+    <ClCompile Include="src\cpp\analysis\MacroSignature.cpp">
+      <Filter>Source Files\analysis</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>
\ No newline at end of file
index 3af740e..afe1fdd 100644 (file)
@@ -39,8 +39,9 @@ struct MacroSignature
     const std::wstring name;
     const unsigned int lhs;
     TITypeSignatureTuple tuple;
+    std::size_t exp_hash;
 
-    MacroSignature(MacroDef & macrodef, const unsigned int _lhs, const std::vector<TIType> & in) : name(macrodef.getName()), lhs(_lhs), tuple(in) { }
+    MacroSignature(MacroDef & macrodef, const unsigned int _lhs, const std::vector<TIType> & in);
 
     friend std::wostream & operator<<(std::wostream & out, const MacroSignature & signature)
     {
@@ -73,7 +74,7 @@ struct MacroSignature
     {
         inline bool operator()(const MacroSignature & L, const MacroSignature & R) const
         {
-            return L.lhs == R.lhs && L.name == R.name && L.tuple == R.tuple;
+            return L.lhs == R.lhs && L.name == R.name && L.tuple == R.tuple && L.exp_hash == R.exp_hash;
         }
     };
 };
index cf5dff1..111de9a 100644 (file)
@@ -141,11 +141,32 @@ public:
     bool isValidVariableName(const wchar_t*);
     bool isValidVariableName(const char*);
 
-    inline bool isOriginalSymbol(const symbol::Symbol & sym) const
+    inline bool isOriginalSymbol(const symbol::Symbol & sym)
     {
-        return getLevel(sym) == 0;
+        //builtin
+        if (getLevel(sym) == 0)
+        {
+            return true;
+        }
+
+        Variable* var = getOrCreate(sym);
+        if (var->empty())
+        {
+            //check libraries
+
+            //if sym exists, it is obviously the original
+            if (libraries.get(sym, SCOPE_ALL) != nullptr)
+            {
+                return true;
+            }
+        }
+        else
+        {
+            return var->count() == 1;
+        }
+
+        return false;
     }
-
 private:
 
     types::InternalType* get(const Symbol& key, int _iLevel);
index f91e565..3e21ce6 100644 (file)
@@ -96,6 +96,11 @@ struct EXTERN_AST Variable
         }
     }
 
+    inline int count() const
+    {
+        return (int)stack.size();
+    }
+
     inline Symbol getSymbol() const
     {
         return name;
diff --git a/scilab/modules/ast/src/cpp/analysis/MacroSignature.cpp b/scilab/modules/ast/src/cpp/analysis/MacroSignature.cpp
new file mode 100644 (file)
index 0000000..ae284b3
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+*  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+*  Copyright (C) 2014 - Scilab Enterprises - Calixte DENIZET
+*
+* Copyright (C) 2012 - 2016 - Scilab Enterprises
+*
+* This file is hereby licensed under the terms of the GNU GPL v2.0,
+* pursuant to article 5.3.4 of the CeCILL v.2.1.
+* This file was originally licensed under the terms of the CeCILL v2.1,
+* and continues to be available under such terms.
+* For more information, see the COPYING file which you should have received
+* along with this program.
+*
+*/
+
+#include "data/MacroSignature.hxx"
+#include "data/MacroDef.hxx"
+#include "serializervisitor.hxx"
+
+static std::size_t uchar_array_hasher(unsigned char const* vec, std::size_t len) {
+    std::size_t ret = len;
+    for (int i = 0; i < len; ++i) {
+        ret ^= std::hash<unsigned char>()(vec[i]);
+    }
+    return ret;
+}
+
+namespace analysis {
+
+MacroSignature::MacroSignature(MacroDef & macrodef, const unsigned int _lhs, const std::vector<TIType> & in)
+    : name(macrodef.getName()), lhs(_lhs), tuple(in)
+{
+    const ast::SeqExp& exp = macrodef.getOriginalBody();
+    ast::SerializeVisitor serialMacro(exp.getOriginal());
+    unsigned char* serial = serialMacro.serialize();
+    unsigned int size = *((unsigned int*)serial);
+    exp_hash = uchar_array_hasher(serial, size);
+    free(serial);
+}
+}
\ No newline at end of file
index 0b2b4aa..ab26d79 100644 (file)
@@ -321,15 +321,13 @@ Callable::ReturnValue Macro::call(typed_list &in, optional_list &opt, int _iRetC
         //use version from analyze
         if (m_functionId != -1) 
         {
-            std::wcerr << "macro functionId: " << m_functionId << std::endl;
+            //std::wcerr << "macro functionId: " << m_functionId << std::endl;
             ast::Exp* exp = FBlockListener::getExp(m_functionId);
             if (exp)
             {
-                ast::PrettyPrintVisitor dv(std::wcerr, true, true);
+                //ast::PrettyPrintVisitor dv(std::wcerr, true, true);
                 //m_body->accept(dv);
-                exp->accept(dv);
-
-                //std::wcerr << "exec new exp" << std::endl;
+                //exp->accept(dv);
                 exp->accept(*exec);
             }
             else