add src/doc in gitignore
[nit.git] / src / syntax / mmbuilder.nit
index 542ab77..8999b01 100644 (file)
 package mmbuilder
 
 import syntax_base
+private import primitive_info
+
+redef class ToolContext
+       redef fun handle_property_conflict(lc, impls)
+       do
+               var location: nullable Location = null
+               if lc isa MMSrcLocalClass then
+                       var node = lc.node
+                       if node != null then node.location
+               end
+               #if location == null then location = lc.mmmodule.location
+               var clas = new Array[MMLocalClass]
+               for i in impls do
+                       clas.add(i.local_class)
+               end
+               self.fatal_error(location, "Property inheritance conflict in class {lc} for `{impls.first.name}': conflicting properties are defined in {clas.join(", ")}")
+       end
+end
 
 # Class specialization hierarchy sorter
 private class CSHSorter
@@ -163,7 +181,7 @@ redef class MMSrcLocalClass
                        n = n.next_node
                end
 
-               for p in src_local_properties do
+               for p in src_local_properties.values do
                        p.accept_property_visitor(v)
                end
        end
@@ -197,7 +215,7 @@ redef class MMSrcLocalClass
 
                # Collect unassigned attributes
                var unassigned_attributes = new Array[MMSrcAttribute]
-               for a in src_local_properties do
+               for a in src_local_properties.values do
                        if a isa MMSrcAttribute then
                                var n = a.node
                                if n.n_expr == null then unassigned_attributes.add(a)
@@ -302,7 +320,11 @@ redef class MMImplicitInit
                for a in unassigned_attributes do
                        var sig = a.signature
                        if sig == null then return # Broken attribute definition
-                       params.add( new MMParam( sig.return_type.as(not null), once "recv".to_symbol))
+                       var name = a.name
+                       if name.to_s.first == '_' or name.to_s.first == '@' then
+                               name = a.to_s.substring_from(1).to_symbol
+                       end
+                       params.add(new MMParam(sig.return_type.as(not null), name))
                end
                signature = new MMSignature(params, null, local_class.get_type)
        end
@@ -522,7 +544,7 @@ redef class AClassdef
                var local_class: MMSrcLocalClass
                var mod = v.mmmodule
                var local_classes = mod.src_local_classes
-               if (local_classes.has_key(name)) then
+               if local_classes.has_key(name) then
                        local_class = local_classes[name]
                        _local_class = local_class
                        if self isa AStdClassdef then
@@ -954,6 +976,8 @@ redef class APropdef
                                                t = v.type_array(t)
                                        end
                                        p.variable.stype = t
+
+                                       isig.params[p.position].name = p.variable.name
                                end
                                s = isig
                                prop.signature = s
@@ -1191,68 +1215,6 @@ redef class AExternPropdef
        end
 end
 
-redef class MMMethod
-       fun default_extern_name : String
-       do
-               return "{friendly_extern_name(local_class)}___impl"
-       end
-
-       # Friendly name for this method. Is mainly the class name followed by the
-       # function name. It is prefixed with "new" for a constructor.
-       fun friendly_extern_name( local_class : MMLocalClass ) : String
-       do
-               if not is_init then
-                       var native_fun_name : String
-                       var method_name = name.to_s
-                       if method_name == "+" then
-                               native_fun_name = "_plus" # add
-                       else if method_name == "-" then
-                               native_fun_name = "_minus" # sub
-                       else if method_name == "*" then
-                               native_fun_name = "_star" # multi
-                       else if method_name == "/" then
-                               native_fun_name = "_slash" # div
-                       else if method_name == "%" then
-                               native_fun_name = "_percent" # mod
-                       else if method_name == "[]" then
-                               native_fun_name = "_index" # brackets
-                       else if method_name == "[]=" then
-                               native_fun_name = "_index_assign" # brackets
-                       else if method_name == "==" then
-                               native_fun_name = "_equal" # eq
-                       else if method_name == "<" then
-                               native_fun_name = "_less" # lt
-                       else if method_name == ">" then
-                               native_fun_name = "_greater" # gt
-                       else if method_name == "<=" then
-                               native_fun_name = "_less_or_equal" # greater_or_equal
-                       else if method_name == ">=" then
-                               native_fun_name = "_ge" # smaller_or_equal
-                       else if method_name == "!=" then
-                               native_fun_name = "_not_equal" # bang
-                       else if method_name == ">>" then
-                               native_fun_name = "_right"
-                       else if method_name == "<<" then
-                               native_fun_name = "_left"
-                       else if method_name == "<=>" then
-                               native_fun_name = "_starship"
-                       else if method_name[ method_name.length-1 ] == '=' then
-                               native_fun_name = "{method_name.substring(0,method_name.length-1)}__assign"
-                       else
-                               native_fun_name = method_name
-                       end
-
-                       return "{local_class.name}_{native_fun_name}"
-               else
-                       if name == once "init".to_symbol then
-                               return "new_{local_class.name}"
-                       else
-                               return "new_{local_class.name}_{name}"
-                       end
-               end
-       end
-end
-
 redef class ATypePropdef
        redef fun prop do return _prop.as(not null)
        var _prop: nullable MMSrcTypeProperty