Find and replace all occurrence of a function definition - visual-studio

I want to delete all occurrences of a function definition.
I have a lot of member functions with the same prototype overloaded in multiple derived classes
For example,
void **********::func()
{
.
..
...
}
The above function definition are different in number of lines in each occurrence.
Is there a way to do this in visual studio? If not in notepad++ or some other editor?

Related

How to specify the type signature to find a specific method with InteractiveUtils.edit in Julia?

In order to quickly find the implementation of some methods I would like to use InteractiveUtils.edit.
E.g. if I wanted to see the implementation of methodswith I should be able to write something like edit(methodswith). However, as the methodswith function has multiple methods I get:
ERROR: function has multiple methods; please specify a type signature
How do I specify the type signature? I know that I can find out which methods there are with methods(methodswith), giving signatures like this:
[1] methodswith(t::Type; supertypes) in InteractiveUtils at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/InteractiveUtils/src/InteractiveUtils.jl:169
How can I plug this into a call of edit?
I know that there is #edit which I could use with some exemplary function call. However, sometimes it would be more straightforward to just specify the types, because constructing the objects for an exemplary call of the method also involves some investigation for valid constructors.
TL;DR:
How to find a specific method of a function with InteractiveUtils.edit in Julia?
Just pass argument types as a tuple in the second positional argument to edit.
For example edit(sin, (Int,)) will open you the definition of sin that is used with one argument of type Int.
Note that this might fail if you want to edit a function from stdlib (for functions from Base or non-standard libraries edit will work properly).
In such a case you have to use methods function and locate the file manually. For example:
julia> using Statistics
julia> edit(mean, (Vector{Int},)) # this might not work as expected
julia> methods(mean, (Vector{Int},))
# 1 method for generic function "mean":
[1] mean(A::AbstractArray; dims) in Statistics at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.1\Statistics\src\Statistics.jl:132
Now you have a file name and a line number where the method is located, but the path may be wrong, so you have to find the file yourself in the Julia installation folder.
Here is how you can retrieve this information programatically (assuming you have specified the args correctly and only one method matches). First define a function:
function edit_stdlib(fun, args)
m = methods(fun, args)
#assert length(m.ms) == 1 # assume we have an exact match
p = joinpath(Sys.STDLIB, splitpath(string(m.ms[1].file))[end-2:end]...)
l = m.ms[1].line
edit(p, l)
end
and now you can write e.g. edit_stdlib(mean, (Vector{Int},)) to get what you want.

alloy: arity issue when checking constraint with an assertion

I've recently started to experiment with alloy for a project, and I have run into an issue unequal arities. Here is a simplified example. I have four signatures:
Word
Definition
Document: a document has a text (a sequence of words)
Dictionary: a dictionary maps a sequence of words to a sequence of definitions (to keep it simple, let's say that a word should have exactly one definition)
Here is a minimal code example:
module dictionaries
open util/relation as relation
sig Word {}
sig Definition {}
sig Document {
text: seq Word
}
sig Dictionary {
entries: seq Word,
defseq: seq Definition,
define: Word->Definition,
}{
//dictionary maps word to def only for the word present in dictionary
dom[define] = elems [entries] function [define, elems [entries]]
//content of the list of defintions
defseq = entries.define
}
//assert all word in a dictionary have a definition
assert all_word_defined {
all w: Word | all dict: Dictionary | some def: Definition |
//w in dict.entries implies w->def in dict.define
}
check all_word_defined
So my questions are:
How do I constrain dictionaries so that each word in the dictionary maps to exactly one definition? Is it correct to do it as in the code above?
How do I check that this constraint is respected with an assertion? Obviously the bit of code w in dict.entries implies w->def in dict.define does not work, because w in dict.entriesand w->def in dict.define do not have the same arity, and I get the error message "in can be used only between 2 expressions of the same arity"...
I think you're struggling with seq and assertions more than arity.
seq is not very common in Alloy, you only use it when you need to change the ordering of elements. In this example, I do not see any need for ordering in the current description.
Assertions verify invariants of the whole model. What you try to assert is more a fact that you state in the model than what you assert. Assertions are useful if you have defined operations and want to verify that certain things can never happen regardless of how those operations are executed and in what order. I.e. the assertions verify the consequences of the model, not the facts. (Although sometimes it is useful to verify something in other words.)
Alloy is incredibly powerful in navigating through global tables. Despite looking object oriented, the trick is to understand that fields are actually global tables that are joined. (This is what took me a long time to get.)
You should not have redundant information in the model. You entries, defseq and define can be modelled with functions on the define table.
The base language is very powerful. For a problem of this size you often do not need any utilities. Especially relation seems quite redundant after you feel the relational model of Alloy.
Ok, step by step:
A Documents is a sequence of words:
I would just make a Document a set of Word because that more natural and a lot easier to use. In this problem, the ordering of words does not play a role so using normal sets is ok it seems? (Counting the words would require a seq.)
sig Word {}
sig Document {
text: Word
}
A dictionary maps a sequence of words to a sequence of definitions (to keep it simple, let's say that a word should have exactly one definition)
I think you mean that a Dictionary can map a word to one definition? Does EVERY word have an entry? Or are there some words that have an entry? You say 'a' which I take as some words having one Definition? If so:
sig Definition {}
sig Dictionary {
define : Word -> one Definition,
}
The define table (which is Dictionary->Word->Definition) has a constrain that for a given Dictionary->Word combination, there must be one Definition. This means not all Words have to be in the table, but if a Word is in the table then there must be exactly one Definition. (you can model this also with other constraints. Best is to write out a table and look at the columns.)
You define entries as the set of Word in the Dictionary. You can model this better as a function:
fun Dictionary.entries : set Word {
this.define.univ
}
The first join selects the this Dictionary in the define table and removes the first column. The second join removes the last column.
And similar for defseq:
fun Dictionary.defseq : set Definition {
this.define[univ]
}
The box join [] just joins the inside of the square brackets with the first column of the table before it, leaving the Definition column. That is:
(univ).(this.define)
How do I check that this constraint is respected with an assertion
I think it is not clear what you try to assert. (Which is the power of a formal language that you discover this!) In Alloy you state as a fact that a Word in a Dictionary maps to one Definition. There is no use asserting something you have defined as a fact. Before you can assert you first need more definitions.
Normally you start writing a predicate and then look for examples of your model. For example, if we want to see one of the infinite Dictionary's then we could write:
pred show( d : Dictionary ) {
d.define.univ = Word
}
run show for 5
In this example, you will see a Dictionary where every word has a Definition.
I've written a blog that might be useful for you: http://aqute.biz/2017/07/15/Alloy.html

Is there a way to programmatically evaluate a macro?

For example, let us take this code:
Method m()
{
$$$someMacro
}
Or:
Method m(foo as whatever)
{
$$$otherMacro(foo)
}
Provided that I can extract someMacro and otherMacro from the code samples above, is there a way to programmatically expand them?
No. Macro can only be resolved at compile time. Since what macro expands into may depend on where in code macro is placed you can't expand one macro without context.

Member-function definition doesn't see "using declaration" in cpp file

There is a round function in a project in a separate namespace:
namespace CMMN
{
inline long round (double x) { return long (x < 0. ? x-0.5 : x+0.5); }
}
Some class is declared in a *.h file and it's member functions are defined in a separate *.cpp file:
using CMMN::round;
long SOME_CLASS::MemberFunction()
{
return round(sqrt(m_SomeValue));
}
The problem is that compiler generates an error:
error C2668: 'CMMN::round' : ambiguous call to overloaded function
...\commdef.h(222): could be 'long CMMN::round(double)'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\math.h(1241): or 'long double round(long double) throw()'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\math.h(1125): or 'float round(float) throw()'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\math.h(516): or 'double round(double)'
while trying to match the argument list '(double)'
I wonder why ussing declaration in the begining of the cpp file does
not affect memeber function definitions below?
Is there a way to make
using declaration be seen inside member function definition? Adding using declaration for each function definition inside is a decision, but it is almost equivalent to full-qualified round calls.
Thanks in advance.
It does affect it. The compiler is telling you that there are 4 candidate functions that it could call, and it doesn't know which one to call. One of those candidates is CMMN::round, which shows that the using declaration is being recognized.
You have to disambiguate which round() you intend for it to call.
using CMMN::round within a namespace only makes that symbol visible within said namespace; it does not affect binding preference.
You appear to have also included <cmath> or <math.h> somewhere, which also declare overloads of round.
You will have to either place using declarations within function definitions, or fully qualify their names where they are used.

dumping the source code for an anonymous function

original (update follows)
I'm working with a lot of anonymous functions, ie functions declared as part of a dictionary, aka "methods". It's getting pretty painful to debug, because I can't tell what function the errors are happening in.
Vim's backtraces look like this:
Error detected while processing function NamedFunction..2111..2105:
line 1:
E730: using List as a String
This trace shows that the error occurred in the third level down the stack, on the first line of anonymous function #2105. IE NamedFunction called anonymous function #2111, which called anonymous function #2105. NamedFunction is one declared through the normal function NamedFunction() ... endfunction syntax; the others were declared using code like function dict.func() ... endfunction.
So obviously I'd like to find out which function has number 2105.
Assuming that it's still in scope, it's possible to find out what Dictionary entry references it by dumping all of the dictionary variables that might contain that reference. This is sort of awkward and it's difficult to be systematic about it, though I guess I could code up a function to search through all of the loaded dictionaries for a reference to that function, watching out for circular references. Although to be really thorough, it would have to search not only script-local and global dictionaries, but buffer-local dictionaries as well; is there a way to access another buffer's local variables?
Anyway I'm wondering if it's possible to dump the source code for the anonymous function instead. This would be a lot easier and probably more reliable.
update
I ended up asking about this a while back on the vim_use mailing list. Bram Moolenar, aka vim's BDFL, responded by saying that "You are not supposed to use the function number." However, a suitable alternative for this functionality has not been suggested, as of early September 2010. It's also not been explicitly mentioned whether or not this functionality will continue to work in subsequent vim releases. I've not tried to do this (or anything else, for that matter) in the recently released vim 7.3.
The :function command tries to stop you from specifying the numbered functions (their name is just a number) but you can trick it using the {...} dynamic function name feature, throw in some :verbose and you have a winner:
:verbose function {43}
function 43()
Last set from /home/peter/test.vim
1 throw "I am an exception"
endfunction
This was not at all obvious in the help docs.
I use the following workaround: I have one plugin that does some stuff like creating commands, global functions for other plugins. It also registers all plugins, so I have a large dictionary with lots of stuff related to plugins. If I see a error I search for a function that produces it using function findnr:
"{{{3 stuf.findf:
function s:F.stuf.findf(nr, pos, d)
if type(a:d)==2 && string(a:d)=~#"'".a:nr."'"
return a:pos
elseif type(a:d)==type({})
for [key, Value] in items(a:d)
let pos=s:F.stuf.findf(a:nr, a:pos."/".key, Value)
unlet Value
if type(pos)==type("")
return pos
endif
endfor
endif
return 0
endfunction
"{{{3 stuf.findr:
function s:F.stuf.findnr(nr)
for [key, value] in items(s:g.reg.registered)+[["load", {"F": s:F}]]
let pos=s:F.stuf.findf(a:nr, "/".key, value.F)
if type(pos)==type("")
return pos
endif
endfor
return 0
endfunction
Here I have this plugin functions in s:F.{key} dictionaries and other plugins' functions under s:g.reg.registered[plugname].F dictionary.

Resources