Re[2]: [CEDET-devel] Bug in semantic-el.el and a nifty new parser for defalias
Brought to you by:
zappo
From: Eric M. L. <er...@si...> - 2005-01-05 14:21:09
|
>>> David PONCE <dav...@wa...> seems to think that: >Hi Eric, > >> Fixing defstruct parsing sounds like a good idea. I'm not surprised >> it was broken as I probably never tested it. > >OK, I committed the fix. Thanks >> C has something like an alias that you can declare in a "typedef", >> and it is a special kind of type which is the type it is aliasing >> through the "parent" slot. >> >> A function being aliased will not always be loaded into Emacs for >> the finding so it may be unreliable to attempt any extra extraction. >> It may be best to postpone such searching till later for other reasons >> as well. For example with these definitions: >> >> Emacs Lisp: >> (defalias 'newsym 'oldsym "why an alias") >> (defalias 'newsym (lambda (a) "Say what?") "What say?") >> >> C: >> #define NEWSYM oldsym >> >> These ought to be addressed in the same way, though the C one isn't >> captured in the TAG structure yet. It may be that an "alias" is >> something special to deal with for multiple languages. For example: >> >> (semantic-format-tag-summarize ALIAS) >> Alias: ALIAS == SOURCE-OF-ALIAS >> >> and the analyzer would then be able to correctly translate anything >> marked as an alias for something else. This could be >> valuable... depending on the prevalence of aliasing languages. It >> would certainly make some aspects of the C pre-processor much easier >> to deal with. > >Good points Eric! So what do you think of this definition inspired >from what the C parser produces for typedefs? > >(semantic-elisp-setup-form-parser > (lambda (form start end) > (let ((alias (nth 1 form))) > (semantic-tag-new-type > ;; If not a quoted symbol evaluate the alias expression. > ;; Signal an error if the alias is not a symbol. > (symbol-name (if (eq (car alias) 'quote) > (cadr alias) > (eval alias))) > "typedef" ;; Indicate an alias > nil nil > ;; The following attribute hold the aliased definition. > :typedef (nth 2 form) > ))) > defalias > ) [ ... ] The typedef I used previously was merely mimicking the nature of the C language. If a goal is to tackle an "alias" so it can be used in different languages, then perhaps a notation like this would be good. (Using very loose grammar notation) (ALIAS-TAG "name" 'meta-tag-class "value") Thus defalias: open-paren DEFALIAS symbol symbol opt-docstring close-paren (ALIAS-TAG $3 'function $4 :documentation $5) ; defvaralias: open-paren DEFVARALIAS symbol symbol opt-docstring close-paren (ALIAS-TAG $3 'variable $4 :documentation $5) ; or in C: typedef: TYPEDEF old_c_type new_name (ALIAS-TAG $3 'type $2) ; macro: HASH DEFINE name expression (ALIAS-TAG $3 nil $4) ; Now in C code, you might have this: #define MOOSE 1 #define PENGUIN (a->b) #define EMU (a->b.c) int myfunc(sometype a) { int tmp = PENGUIN-!- return EMU + MOOSE; } The tooltip like help for PENGUIN, EMU or MOOSE would be the literal translation from the alias. On the other hand, if the cursor were at the -!- location and completions were requested, the name of the alias would be found as complete, but a substitution would be needed, at which point the completion engine may find that ".c" would be a good completion. In Emacs Lisp code like this: (defalias 'this 'that) (defun myfunc () (this -!-)) the tool help would show that "this" is "that". Because it has a meta-tag-class of 'function, it would choose to look up "that" and extract the argument list. Big Lofty Goals. The best kind. ;) Would this aliasing mechanism be used in other languages besides C and Lisp? Additional thoughts would be useful. Thanks. Eric -- Eric Ludlam: za...@gn..., er...@si... Home: http://www.ludlam.net Siege: www.siege-engine.com Emacs: http://cedet.sourceforge.net GNU: www.gnu.org |