Skip to content

Commit

Permalink
[feature] First stab at Move Function
Browse files Browse the repository at this point in the history
  • Loading branch information
thoni56 committed May 7, 2024
1 parent 9b5aacc commit 83631a5
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 96 deletions.
14 changes: 10 additions & 4 deletions editors/emacs/c-xref.el
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
(list c-xref_PPC_AVR_EXTRACT_FUNCTION "Extract Function" 'c-xref-extract-function nil)
(list c-xref_PPC_AVR_EXTRACT_MACRO "Extract Macro" 'c-xref-extract-macro nil)
(list c-xref_PPC_AVR_EXTRACT_VARIABLE "Extract Variable" 'c-xref-extract-variable nil)
(list c-xref_PPC_AVR_MOVE_FUNCTION "Move Function" 'c-xref-move-function nil)
(list c-xref_PPC_AVR_SET_MOVE_TARGET "Set Target for Next Moving Refactoring" 'c-xref-set-moving-target-position nil)
(list c-xref_PPC_AVR_UNDO "Undo Last Refactoring" 'c-xref-undo-last-refactoring nil)
))
Expand Down Expand Up @@ -3374,7 +3375,7 @@ Special hotkeys available:
(setq i (c-xref-server-dispatch-skip-blank ss i len))
(while (and (< i len)) ;; (eq (elt ss i) ?<))
(setq i (c-xref-server-parse-xml-tag ss i len))
;;(message "tag == %s" c-xref-server-ctag)
(message "tag == %s" c-xref-server-ctag)
(cond
(
(equal c-xref-server-ctag c-xref_PPC_SET_INFO)
Expand All @@ -3385,9 +3386,6 @@ Special hotkeys available:
(
(equal c-xref-server-ctag c-xref_PPC_SINGLE_COMPLETION)
(setq i (c-xref-server-dispatch-single-completion ss i len dispatch-data)))
(
(equal c-xref-server-ctag c-xref_PPC_FQT_COMPLETION)
(setq i (c-xref-server-dispatch-fqt-completion ss i len dispatch-data)))
(
(equal c-xref-server-ctag c-xref_PPC_GOTO)
(setq i (c-xref-server-dispatch-goto ss i len dispatch-data)))
Expand Down Expand Up @@ -7346,6 +7344,14 @@ refactoring.
)
))

(defun c-xref-move-function (rd)
(let ((name))
(setq name (c-xref-get-identifier-on-point))
(c-xref-refactoring-init-actions (format "moving %s" name))
(c-xref-moving '("-rfct-move-function"))
(c-xref-refactoring-finish-actions)
))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; EXTRACT METHOD ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Expand Down
14 changes: 1 addition & 13 deletions editors/emacs/c-xrefprotocol.el
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@






;;; DO NOT EDIT!!!
;;; AUTOGENERATED from src/protocol & src/refactorings using Makefile

Expand All @@ -17,7 +11,6 @@
(defconst c-xref_PPC_ALL_COMPLETIONS "all-completions")
(defconst c-xref_PPC_MULTIPLE_COMPLETION_LINE "cl")
(defconst c-xref_PPC_SINGLE_COMPLETION "single-completion")
(defconst c-xref_PPC_FQT_COMPLETION "fqt-completion")
(defconst c-xref_PPC_SYMBOL_LIST "symbol-list")

(defconst c-xref_PPC_CALL_MACRO "macro")
Expand Down Expand Up @@ -115,14 +108,9 @@
(defconst c-xref_PPC_AVR_ADD_PARAMETER 40)
(defconst c-xref_PPC_AVR_DEL_PARAMETER 50)
(defconst c-xref_PPC_AVR_MOVE_PARAMETER 60)
(defconst c-xref_PPC_AVR_PULL_UP_FIELD 120)
(defconst c-xref_PPC_AVR_PULL_UP_METHOD 130)
(defconst c-xref_PPC_AVR_PUSH_DOWN_FIELD 140)
(defconst c-xref_PPC_AVR_PUSH_DOWN_METHOD 150)
(defconst c-xref_PPC_AVR_MOVE_FUNCTION 70)
(defconst c-xref_PPC_AVR_EXTRACT_FUNCTION 230)
(defconst c-xref_PPC_AVR_EXTRACT_MACRO 240)
(defconst c-xref_PPC_AVR_EXTRACT_VARIABLE 250)
(defconst c-xref_PPC_AVR_SET_MOVE_TARGET 290)
(defconst c-xref_PPC_AVR_UNDO 300)


9 changes: 3 additions & 6 deletions src/cxref.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ static void setAvailableRefactorings(Symbol *symbol) {
case TypeVoid:
case TypePointer:
case TypeArray:
case TypeFunction:
case TypeAnonymousField:
case TypeError:
case TypeElipsis:
Expand All @@ -135,6 +134,7 @@ static void setAvailableRefactorings(Symbol *symbol) {
case TypeNonImportedClass:
case TypeInducedError:
case TypeInheritedFullMethod:
case TypeFunction:
case TypeSpecialConstructorCompletion:
case TypeUnknown:
case TypeDefault:
Expand All @@ -144,6 +144,7 @@ static void setAvailableRefactorings(Symbol *symbol) {
makeRefactoringAvailable(PPC_AVR_ADD_PARAMETER, "");
makeRefactoringAvailable(PPC_AVR_DEL_PARAMETER, "");
makeRefactoringAvailable(PPC_AVR_MOVE_PARAMETER, "");
makeRefactoringAvailable(PPC_AVR_MOVE_FUNCTION, "");
}
break;
case MODIFIERS_START:
Expand Down Expand Up @@ -1675,11 +1676,7 @@ static void olCompletionSelect(void) {
if (options.xref2) {
assert(sessionData.completionsStack.root!=NULL);
ppcGotoPosition(&sessionData.completionsStack.root->callerPosition);
if (rr->csymType==TypeNonImportedClass) {
ppcGenRecord(PPC_FQT_COMPLETION, rr->name);
} else {
ppcGenRecord(PPC_SINGLE_COMPLETION, rr->name);
}
ppcGenRecord(PPC_SINGLE_COMPLETION, rr->name);
} else {
gotoOnlineCxref(&refs->callerPosition, UsageUsed, rr->name);
}
Expand Down
3 changes: 3 additions & 0 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,9 @@ static bool processROption(int *argi, int argc, char **argv) {
else if (strcmp(argv[i], "-rfct-move-param")==0) {
options.theRefactoring = AVR_MOVE_PARAMETER;
}
else if (strcmp(argv[i], "-rfct-move-function")==0) {
options.theRefactoring = AVR_MOVE_FUNCTION;
}
else if (strcmp(argv[i], "-rfct-extract-function")==0) {
options.theRefactoring = AVR_EXTRACT_FUNCTION;
}
Expand Down
10 changes: 1 addition & 9 deletions src/protocol.th
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ PROTOCOL_ITEM(String, PPC_FULL_MULTIPLE_COMPLETIONS, "full-completions")
PROTOCOL_ITEM(String, PPC_ALL_COMPLETIONS, "all-completions")
PROTOCOL_ITEM(String, PPC_MULTIPLE_COMPLETION_LINE, "cl")
PROTOCOL_ITEM(String, PPC_SINGLE_COMPLETION, "single-completion")
PROTOCOL_ITEM(String, PPC_FQT_COMPLETION, "fqt-completion")
PROTOCOL_ITEM(String, PPC_SYMBOL_LIST, "symbol-list")

PROTOCOL_ITEM(String, PPC_CALL_MACRO, "macro")
Expand All @@ -21,15 +20,12 @@ PROTOCOL_ITEM(String, PPC_REFACTORING_PASTE_BLOCK, "paste-block")


PROTOCOL_ITEM(String, PPC_ASK_CONFIRMATION, "ask-confirmation")
PROTOCOL_ITEM(String, PPC_ADD_TO_IMPORTS_DIALOG, "add-to-imports-dialog")
PROTOCOL_ITEM(String, PPC_EXTRACTION_DIALOG, "extraction-dialog")

PROTOCOL_ITEM(String, PPC_DISPLAY_RESOLUTION, "display-resolution")
PROTOCOL_ITEM(String, PPC_DISPLAY_OR_UPDATE_BROWSER, "display-or-update-browser")
PROTOCOL_ITEM(String, PPC_SYMBOL_RESOLUTION, "resolution")
PROTOCOL_ITEM(String, PPC_SYMBOL, "symbol")
PROTOCOL_ITEM(String, PPC_VIRTUAL_SYMBOL, "virtual-symbol")
PROTOCOL_ITEM(String, PPC_CLASS, "class")

PROTOCOL_ITEM(String, PPC_REFERENCE_LIST, "reference-list")
PROTOCOL_ITEM(String, PPC_SRC_LINE, "src-line")
Expand All @@ -47,7 +43,6 @@ PROTOCOL_ITEM(String, PPC_BOTTOM_INFORMATION, "bottom-information")
PROTOCOL_ITEM(String, PPC_DEBUG_INFORMATION, "debug-information")

PROTOCOL_ITEM(String, PPC_GOTO, "goto")
PROTOCOL_ITEM(String, PPC_BROWSE_URL, "browse-url")
PROTOCOL_ITEM(String, PPC_FILE_SAVE_AS, "file-save-as")
PROTOCOL_ITEM(String, PPC_MOVE_FILE_AS, "file-move-as")
PROTOCOL_ITEM(String, PPC_KILL_BUFFER_REMOVE_FILE, "kill-buffer-remove-file")
Expand Down Expand Up @@ -106,10 +101,7 @@ PROTOCOL_ITEM(int, PPC_AVR_RENAME_MODULE, AVR_RENAME_MODULE)
PROTOCOL_ITEM(int, PPC_AVR_ADD_PARAMETER, AVR_ADD_PARAMETER)
PROTOCOL_ITEM(int, PPC_AVR_DEL_PARAMETER, AVR_DEL_PARAMETER)
PROTOCOL_ITEM(int, PPC_AVR_MOVE_PARAMETER, AVR_MOVE_PARAMETER)
PROTOCOL_ITEM(int, PPC_AVR_PULL_UP_FIELD, AVR_PULL_UP_FIELD)
PROTOCOL_ITEM(int, PPC_AVR_PULL_UP_METHOD, AVR_PULL_UP_METHOD)
PROTOCOL_ITEM(int, PPC_AVR_PUSH_DOWN_FIELD, AVR_PUSH_DOWN_FIELD)
PROTOCOL_ITEM(int, PPC_AVR_PUSH_DOWN_METHOD, AVR_PUSH_DOWN_METHOD)
PROTOCOL_ITEM(int, PPC_AVR_MOVE_FUNCTION, AVR_MOVE_FUNCTION)
PROTOCOL_ITEM(int, PPC_AVR_EXTRACT_FUNCTION, AVR_EXTRACT_FUNCTION)
PROTOCOL_ITEM(int, PPC_AVR_EXTRACT_MACRO, AVR_EXTRACT_MACRO)
PROTOCOL_ITEM(int, PPC_AVR_EXTRACT_VARIABLE, AVR_EXTRACT_VARIABLE)
Expand Down
5 changes: 1 addition & 4 deletions src/refactorings.def
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
#define AVR_ADD_PARAMETER 40
#define AVR_DEL_PARAMETER 50
#define AVR_MOVE_PARAMETER 60
#define AVR_PULL_UP_FIELD 120
#define AVR_PULL_UP_METHOD 130
#define AVR_PUSH_DOWN_FIELD 140
#define AVR_PUSH_DOWN_METHOD 150
#define AVR_MOVE_FUNCTION 70
#define AVR_EXTRACT_FUNCTION 230
#define AVR_EXTRACT_MACRO 240
#define AVR_EXTRACT_VARIABLE 250
Expand Down
5 changes: 1 addition & 4 deletions src/refactorings.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ typedef enum Refactorings {
AVR_ADD_PARAMETER = 40,
AVR_DEL_PARAMETER = 50,
AVR_MOVE_PARAMETER = 60,
AVR_PULL_UP_FIELD = 120,
AVR_PULL_UP_METHOD = 130,
AVR_PUSH_DOWN_FIELD = 140,
AVR_PUSH_DOWN_METHOD = 150,
AVR_MOVE_FUNCTION = 70,
AVR_EXTRACT_FUNCTION = 230,
AVR_EXTRACT_MACRO = 240,
AVR_EXTRACT_VARIABLE = 250,
Expand Down
3 changes: 3 additions & 0 deletions src/refactory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,9 @@ void refactory(void) {
parameterManipulation(point, refactoringOptions.theRefactoring, refactoringOptions.olcxGotoVal,
refactoringOptions.parnum2);
break;
case AVR_MOVE_FUNCTION:
errorMessage(ERR_INTERNAL, "Not implemented yet!");
break;
case AVR_EXTRACT_FUNCTION:
progressFactor = 1;
extractFunction(point, mark);
Expand Down
4 changes: 4 additions & 0 deletions tests/test_get_available_refactorings_without_mark/expected
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ end-of-options
<int val=40 len=<n>></int>
<int val=50 len=<n>></int>
<int val=60 len=<n>></int>
<int val=70 len=<n>></int>
<int val=300 len=<n>></int>
</available-refactorings>
-olcxgetrefactorings "-olcursor=382" "CURDIR/parameter.c" -encoding=european -xrefrc "CURDIR/.c-xrefrc" -p "CURDIR"
Expand All @@ -32,6 +33,7 @@ end-of-options
<int val=40 len=<n>></int>
<int val=50 len=<n>></int>
<int val=60 len=<n>></int>
<int val=70 len=<n>></int>
<int val=300 len=<n>></int>
</available-refactorings>
-olcxgetrefactorings "-olcursor=612" "CURDIR/parameter.c" -encoding=european -xrefrc "CURDIR/.c-xrefrc" -p "CURDIR"
Expand All @@ -43,6 +45,7 @@ end-of-options
<int val=40 len=<n>></int>
<int val=50 len=<n>></int>
<int val=60 len=<n>></int>
<int val=70 len=<n>></int>
<int val=300 len=<n>></int>
</available-refactorings>
-olcxgetrefactorings "-olcursor=665" "CURDIR/parameter.c" -encoding=european -xrefrc "CURDIR/.c-xrefrc" -p "CURDIR"
Expand All @@ -54,6 +57,7 @@ end-of-options
<int val=40 len=<n>></int>
<int val=50 len=<n>></int>
<int val=60 len=<n>></int>
<int val=70 len=<n>></int>
<int val=300 len=<n>></int>
</available-refactorings>
-exit
Expand Down
32 changes: 21 additions & 11 deletions tests/test_move_c_function/Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
include ../Makefile.boilerplate

CXREF = ../../src/c-xref
ARGUMENTS = -xrefactory-II -refactory -xrefrc $(CURDIR)/.c-xrefrc -p $(CURDIR) -rfct-move-static-method -movetargetfile=$(CURDIR)/source/target.c -rfct-param1=3 -olmark=33 -olcursor=33 $(CURDIR)/source/source.c

$(TEST): .c-xrefrc
-rm -rf CXrefs
../../src/c-xref -p $(CURDIR) -xrefrc .c-xrefrc -sourcepath sources -create source > CXrefs.output
$(CXREF) $(ARGUMENTS) > output.tmp
$(NORMALIZE) output.tmp > output
$(VERIFY)
$(TEST):
@-$(EDIT_SERVER_DRIVER) commands.input $(EXTRA) > output.tmp
@$(NORMALIZE) output.tmp > output
@diff output expected > /dev/null ; \
if [ $$? -ne 0 ] ; then \
$(FAIL) ; \
echo "diff output expected" ; \
diff output expected ; \
exit 1 ; \
else \
$(OK) ; \
exit 0 ; \
fi

trace: EXTRA = \'-trace\'
trace: $(TEST)

clean:
@-rm -rf .c-xrefrc CXrefs output.tmp output log
rm -rf .c-xrefrc CXrefs output.log output.tmp

DEBUGGER = gdb
gdb debug:
$(DEBUGGER) --args $(CXREF) $(ARGUMENTS)
debug gdb:
@$(EDIT_SERVER_DRIVER) commands.input $(EXTRA) --delay 5 > output.tmp &
sleep 1
sudo gdb -pid `pgrep -a c-xref | grep -v emacs | awk '{ print $$1 }'` -ex 'br setAvailableRefactorings' -ex 'continue'
78 changes: 33 additions & 45 deletions tests/test_move_c_function/expected
Original file line number Diff line number Diff line change
@@ -1,46 +1,34 @@
<update-report>
</update-report>
<update-report>
<information len=<n>>Prescanning classes, please wait.</information>
<information len=<n>>C-xrefactory project: CURDIR</information>
<information len=<n>>CURDIR/source/source.c</information>
<information len=<n>>CURDIR/source/target.c</information>
<information len=<n>>Generating 'CURDIR/CXrefs'</information>
</update-report>
<goto>
<position-off off=33 len=<n>>CURDIR/source/source.c</position-off>
</goto>
<cut-block val=39 len=<n>></cut-block>
<goto>
<position-off off=32 len=<n>>CURDIR/source/target.c</position-off>
</goto>
<paste-block len=<n>></paste-block>
<goto>
<position-off off=36 len=<n>>CURDIR/source/target.c</position-off>
</goto>
<replacement>
<str len=<n>>private </str> <str len=<n>></str>
</replacement>
<goto>
<position-off off=36 len=<n>>CURDIR/source/target.c</position-off>
</goto>
<replacement>
<str len=<n>></str> <str len=<n>>public </str>
</replacement>
<goto>
<position-off off=36 len=<n>>CURDIR/source/target.c</position-off>
</goto>
<replacement>
<str len=<n>>public </str> <str len=<n>></str>
</replacement>
<goto>
<position-off off=36 len=<n>>CURDIR/source/target.c</position-off>
</goto>
<replacement>
<str len=<n>></str> <str len=<n>>private </str>
</replacement>
<goto>
<position-off off=58 len=<n>>CURDIR/source/target.c</position-off>
</goto>
<indent-block val=2 len=<n>></indent-block>
../../src/c-xref "-xrefactory-II" "-crlfconversion" "-crconversion" "-encoding=default" "-server" -o server-buffer
-olcxgetprojectname -xrefrc "/home/thoni/Utveckling/c-xrefactory/tests/sandboxed_emacs/.c-xrefrc" "CURDIR/source/target.c"
end-of-options

<sync>
<set-info len=<n>>CURDIR</set-info>
-olcxgetrefactorings "-olcursor=19" "CURDIR/source/target.c" -encoding=european -xrefrc "/home/thoni/Utveckling/c-xrefactory/tests/sandboxed_emacs/.c-xrefrc" -p "CURDIR"
end-of-options

<sync>
<available-refactorings>
<int val=290 len=<n>></int>
<int val=300 len=<n>></int>
</available-refactorings>
-olcxgetprojectname -xrefrc "/home/thoni/Utveckling/c-xrefactory/tests/sandboxed_emacs/.c-xrefrc" "CURDIR/source/source.c"
end-of-options

<sync>
<set-info len=<n>>CURDIR</set-info>
-olcxgetrefactorings "-olcursor=32" "CURDIR/source/source.c" -encoding=european -xrefrc "/home/thoni/Utveckling/c-xrefactory/tests/sandboxed_emacs/.c-xrefrc" -p "CURDIR"
end-of-options

<sync>
<available-refactorings>
<int val=10 len=<n>></int>
<int val=40 len=<n>></int>
<int val=50 len=<n>></int>
<int val=60 len=<n>></int>
<int val=70 len=<n>></int>
<int val=300 len=<n>></int>
</available-refactorings>
-exit
end-of-options

1 change: 1 addition & 0 deletions tests/test_show_available_refactorings/expected
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ end-of-options
<int val=40 len=<n>></int>
<int val=50 len=<n>></int>
<int val=60 len=<n>></int>
<int val=70 len=<n>></int>
<int val=230 len=<n>></int>
<int val=240 len=<n>></int>
<int val=250 len=<n>></int>
Expand Down

0 comments on commit 83631a5

Please sign in to comment.