gEDA-user: [PATCH 3/3] gnetlist: Add access to attribute from components with multiple symbol instances.

2011-01-02 Thread Patrick Bernaud
This commit introduces 'gnetlist:get-all-package-attributes' to
retrieve every first attribute value for package consisting of
multiple symbol instances.

'gnetlist:get-package-attribute' gets redefined to use the above
procedure. To preserve backward compatibility, it returns the first
value found in file order and warns when detecting different, possibly
conflicting values. This behavior is configurable.

Derived from patch #3071482, C code by Sebastian Gieltjes.
---

 gnetlist/include/prototype.h  |2 +-
 gnetlist/scheme/gnet-drc2.scm |4 +++-
 gnetlist/scheme/gnetlist.scm  |   41 ++
 gnetlist/src/g_netlist.c  |   44 -
 gnetlist/src/g_register.c |2 +-
 5 files changed, 72 insertions(+), 21 deletions(-)

diff --git a/gnetlist/include/prototype.h b/gnetlist/include/prototype.h
index d37d397..3a976c2 100644
--- a/gnetlist/include/prototype.h
+++ b/gnetlist/include/prototype.h
@@ -11,7 +11,7 @@ SCM g_get_all_unique_nets(SCM scm_level);
 SCM g_get_all_connections(SCM scm_netname);
 SCM g_get_nets(SCM scm_uref, SCM scm_pin);
 SCM g_get_pins_nets(SCM scm_uref);
-SCM g_get_package_attribute(SCM scm_uref, SCM scm_wanted_attrib);
+SCM g_get_all_package_attributes(SCM scm_uref, SCM scm_wanted_attrib);
 SCM g_get_attribute_by_pinseq(SCM scm_uref, SCM scm_pinseq, SCM 
scm_wanted_attrib);
 SCM g_get_attribute_by_pinnumber(SCM scm_uref, SCM scm_pin, SCM 
scm_wanted_attrib);
 SCM g_get_toplevel_attribute(SCM scm_wanted_attrib);
diff --git a/gnetlist/scheme/gnet-drc2.scm b/gnetlist/scheme/gnet-drc2.scm
index a72f2a4..0570ba4 100644
--- a/gnetlist/scheme/gnet-drc2.scm
+++ b/gnetlist/scheme/gnet-drc2.scm
@@ -430,7 +430,9 @@

(let* ( (numslots_string (gnetlist:get-package-attribute uref 
numslots))
(numslots (string-number numslots_string))
-   (slot_string (gnetlist:get-package-attribute uref slot))
+   (slot_string (let ((slots (gnetlist:get-all-package-attributes 
uref slot)))
+   (if (or (null? slots) (not (car slots)))
+   unknown (car slots
(slot (string-number slot_string))
)
  (let ()
diff --git a/gnetlist/scheme/gnetlist.scm b/gnetlist/scheme/gnetlist.scm
index d798259..70ae135 100644
--- a/gnetlist/scheme/gnetlist.scm
+++ b/gnetlist/scheme/gnetlist.scm
@@ -17,6 +17,8 @@
 ;;; along with this program; if not, write to the Free Software
 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+(use-modules (srfi srfi-1))
+
 ;;--
 ;; The below functions added by SDB in Sept 2003 to support command-line flag
 ;; processing.
@@ -94,6 +96,45 @@
   )
 )
 
+;; Default resolver: returns value associated with first symbol instance
+;; in file order and warns if instances have different values.
+(define (unique-attribute refdes name values)
+(let ((value (car values)))
+  (or (every (lambda (x) (equal? x value)) values)
+  (format (current-error-port) \
+Possible attribute conflict for refdes: ~A
+name: ~A
+values: ~A
+ refdes name values))
+  value)))
+
+(define (gnetlist:get-package-attribute refdes name)
+  Return the value associated with attribute NAME on package
+identified by REFDES.
+
+It actually computes a single value from the full list of values
+produced by 'gnetlist:get-all-package-attributes' as that list is
+passed through 'unique-attribute'.
+
+For backward compatibility, the default behavior is to return the
+value associated with the first symbol instance for REFDES. If all
+instances of REFDES do not have the same value for NAME, it prints a
+warning.
+
+This can be modified by redefining 'unique-attribute' that is a
+procedure that gets provided a non-empty list of attribute values, the
+REFDES and the NAME used for the search. It is expected to return a
+single value as a string or #f for an empty or non-existent attribute
+value.
+
+Note that given the current load sequence of gnetlist, this
+customization can only happen in the backend itself or in a file
+loaded after the backend ('-m' option of gnetlist).
+  (let* ((values (gnetlist:get-all-package-attributes refdes name))
+ (value  (and (not (null? values))
+  (unique-attribute refdes name values
+(or value unknown)))
+
 ;;
 ;; Given a uref, returns the device attribute value (unknown if not defined)
 ;;
diff --git a/gnetlist/src/g_netlist.c b/gnetlist/src/g_netlist.c
index 14441cc..3e1bbe0 100644
--- a/gnetlist/src/g_netlist.c
+++ b/gnetlist/src/g_netlist.c
@@ -472,19 +472,33 @@ SCM g_get_pins_nets(SCM scm_uref)
 }
 
 
-SCM g_get_package_attribute(SCM scm_uref, SCM scm_wanted_attrib)
+/*! \brief Get attribute value(s) from a package with given uref.
+ *  \par Function Description
+ *  This function returns the values of a specific attribute type
+ *  attached to the 

Re: gEDA-user: [PATCH 3/3] gnetlist: Add access to attribute from components with multiple symbol instances.

2011-01-02 Thread Patrick Bernaud
Hi all,

The patch from the parent message has to be replaced by the one
below. Sorry for the inconvenience.

Patrick



multi-part-attribute-search.patch
Description: Binary data


___
geda-user mailing list
geda-user@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user