From 6b57c5bb80239dd545c319b45de7f288b3a260a2 Mon Sep 17 00:00:00 2001 From: Eric Ludlam Date: Wed, 22 Apr 2015 20:56:04 -0400 Subject: [PATCH] semantic: Introduce `semantic-analyze-tag-type-members' * lisp/cedet/semantic/analyze.el (semantic-analyze-tag-type-members) (semantic-analyze-tag-type-members-default): New (semantic-analyze-find-tag-sequence-default) (semantic-analyze-current-context-default): * lisp/cedet/semantic/db-typecache.el (semanticdb-typecache-find): * lisp/cedet/semantic/scope.el (semantic-completable-tags-from-type) (semantic-scope-find): * lisp/cedet/semantic/analyze/complete.el (semantic-analyze-possible-completions-default): * lisp/cedet/semantic/analyze/debug.el (semantic-analyzer-debug-missing-innertype): Use new `semantic-analyze-tag-type-members'. --- lisp/cedet/semantic/analyze.el | 21 +++++++++++++++++++-- lisp/cedet/semantic/analyze/complete.el | 2 +- lisp/cedet/semantic/analyze/debug.el | 2 +- lisp/cedet/semantic/db-typecache.el | 4 +++- lisp/cedet/semantic/scope.el | 6 ++++-- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/lisp/cedet/semantic/analyze.el b/lisp/cedet/semantic/analyze.el index c7062fb24cd..a8cd95d6793 100644 --- a/lisp/cedet/semantic/analyze.el +++ b/lisp/cedet/semantic/analyze.el @@ -219,6 +219,23 @@ Optional argument DESIRED-TYPE may be a non-type tag to analyze." "Try the base, and if that fails, return what we are assigning into." (or (cl-call-next-method) (car-safe (oref context :assignee)))) +;;; TYPE MEMBERS +;; +;; When analyzing tag sequences, we dive through structured data +;; such as structs, classes, unions, etc. The raw member list +;; is sometimes insufficient for generating completions, so each +;; language needs an opportunity to get the type members that are +;; accessable via a code snippet. A key example is anonymous +;; unions in C/C++, whose members are completable in the parent +;; member list, but are structured in the tag as a single item. +(define-overloadable-function semantic-analyze-tag-type-members (tag) + "Return a list of members of TAG, where TAG is a type. +By default, call `semantic-tag-type-members'.") + +(defun semantic-analyze-tag-type-members-default (tag) + "Return a list of members of TAG, where TAG is a type." + (semantic-tag-type-members tag)) + ;;; ANALYSIS ;; ;; Start out with routines that will calculate useful parts of @@ -345,7 +362,7 @@ This function knows of flags: (when miniscope (let ((rawscope (apply 'append - (mapcar 'semantic-tag-type-members tagtype)))) + (mapcar 'semantic-analyze-tag-type-members tagtype)))) (oset miniscope fullscope rawscope))) ) (setq s (cdr s))) @@ -589,7 +606,7 @@ Returns an object based on symbol `semantic-analyze-context'." ;; the found datatype. (setq fcn (semantic-find-tags-by-name (semantic-tag-name (car ty)) - (semantic-tag-type-members (car ty)))) + (semantic-analyze-tag-type-members (car ty)))) (if fcn (let ((lp fcn)) (while lp diff --git a/lisp/cedet/semantic/analyze/complete.el b/lisp/cedet/semantic/analyze/complete.el index 1ddbe131e6a..f99a70bb292 100644 --- a/lisp/cedet/semantic/analyze/complete.el +++ b/lisp/cedet/semantic/analyze/complete.el @@ -235,7 +235,7 @@ FLAGS can be any number of: ((semantic-tag-type (car loopc)) (let ((att (semantic-analyze-tag-type (car loopc) scope)) ) - (if (and att (semantic-tag-type-members att)) + (if (and att (semantic-analyze-tag-type-members att)) (setq c (cons (car loopc) c)))) ) diff --git a/lisp/cedet/semantic/analyze/debug.el b/lisp/cedet/semantic/analyze/debug.el index fd218b67827..eb4e9947ed2 100644 --- a/lisp/cedet/semantic/analyze/debug.el +++ b/lisp/cedet/semantic/analyze/debug.el @@ -307,7 +307,7 @@ possible completions for \"") (princ "\nKnown members of ") (princ (semantic-tag-name dt)) (princ ":\n") - (dolist (M (semantic-tag-type-members dt)) + (dolist (M (semantic-analyze-tag-type-members dt)) (princ " ") ;;(princ (semantic-format-tag-prototype M)) (semantic-analyzer-debug-insert-tag M) diff --git a/lisp/cedet/semantic/db-typecache.el b/lisp/cedet/semantic/db-typecache.el index 8c8cf15eaf2..48e439e54f9 100644 --- a/lisp/cedet/semantic/db-typecache.el +++ b/lisp/cedet/semantic/db-typecache.el @@ -499,7 +499,9 @@ found tag to be loaded." ;; the next set of members. (if (not ans) (setq notdone nil) - (setq stream (semantic-tag-type-members ans))) + ;; When pulling the next stream, only get the members we + ;; are supposed to complete on. + (setq stream (semantic-analyze-tag-type-members ans))) (setq lastans ans ans nil diff --git a/lisp/cedet/semantic/scope.el b/lisp/cedet/semantic/scope.el index 272f37d9858..0ac994cbd49 100644 --- a/lisp/cedet/semantic/scope.el +++ b/lisp/cedet/semantic/scope.el @@ -508,7 +508,9 @@ the access would be 'protected. Otherwise, access is 'public") "Return a list of slots that are valid completions from the list of SLOTS. If a tag in SLOTS has a named parent, then that implies that the tag is not something you can complete from within TYPE." - (let ((allslots (semantic-tag-components type)) + ;; Pull in analyzed type members. + ;; For C, this strips out anon unions, and merges in anon union members. + (let ((allslots (semantic-analyze-tag-type-members type)) (leftover nil) ) (dolist (S allslots) @@ -819,7 +821,7 @@ hits in order, with the first tag being in the closest scope." (if (not ans) (setq typescoperaw nil) (when (cdr namesplit) - (setq typescoperaw (semantic-tag-type-members + (setq typescoperaw (semantic-analyze-tag-type-members (car ans))))) (setq namesplit (cdr namesplit))) -- 2.39.5