I want to replace "function A" call to "function B" call. Currently, I've inserted "function B", I think ReplaceInstWithInst() may help, however, I don't know how to locate "function A". How should I do?
You can access all the functions in a module by using mod->getFunction("functionA");, as described here.
Related
In this basic Crystal program:
class Greeter
def greet(person)
puts "Hello, #{person}!"
end
end
Who is the receiver of #puts? Is it self?
If so, why can't I find a definition for it anywhere?
If not, who is?
The answer, oddly, is nobody! At least not in the Ruby sense.
The Crystal docs make the claim that everything is an object, but there's a slight cheat when it comes to these "top-level" methods.
Unlike Ruby, which puts everything "top-level" into the Kernel module, Crystal has the concept of a "Top Level Namespace", where methods like puts, gets, raise, etc. live.
It doesn't appear to have an identifier associated with it, so you can't inspect/introspect it to find out what exists.
I know this is a somewhat old question, but I just started playing around with Crystal.
In Ruby the top level object is called main, is an instance of class Object and mixes in the Kernel module.
self
#=> main
self.class
#=> Object
self.class.ancestors
#=> [Object, Kernel, BasicObject]
On the other hand the Crystal top level seems to be what the documentation refers to as "The Program", but it seems there's no way to programmatically access that: evaluating self at the top-level gives you the error "there's no self in this scope". For the same reason you can't call inspect without an explicit receiver, since it will just tell you that there's no local variable or method by that name.
I guess the main hint is that the documentation for "[Top Level Namespace]" 2" lists no files in the "Defined In" section which generally lists the classes that define an object.
In short it seems the Crystal developers opted to keep the top level inaccessible, instead of the slightly weird object/class hybrid that main is in Ruby.
I'm using Gecko SDK 32.0.2 for win32.
I have this snippet of code, that should work:
nsCOMPtr<nsIDOMDocument> doc;
dwi->GetDocument(getter_AddRefs(doc));
nsCOMPtr<nsIDOMDocumentXBL> xbl(do_QueryInterface(doc));
But, the compiler says:
no instance of overloaded function 'do_QueryInterface' matches argument list nsCOMPtr<nsIDOMDocument>
Available overloads are:
do_QueryInterface(nsISupports* rawPointer)
and
do_QueryInterface(already_AddRefed<T>&)
How to properly make the function call in this case?
I will self-answer it...
As I've written in the comment, I got no answer on ask.m.o., but I found out the cause.
It was not related to the message directly, it was due to VSC++ project properties:
Treat WChar_t as Built in Type should be set to "Yes (/Zc:wchar_t)"
I'm coming from scripting languages where this js possible, but I'm not sure if this is possible in C++. I'm working with an external module, and it uses a function, which parameters are not correct, so I tried to check them, but is not as simple as in JavaScript.
To check a parameter value, how can I do it? A simple cout gives me errors about types, and the same if I try to convert them to strings.
Is possible see the parameter value as in JS using a console.log(fooParameter); or something similar?
Thank's advanced!
You can try to use breakpoints in your IDE in order to pause the program when callstack reaches that point and see variables.
You can also overload the << operator in order to write to std::cout your parameter type if it's not a predefined one (string, int, etc).
c++ is an explicitly typed language, so you should have full control over what type is being passed.
However, you can print the variable type during runtime with:
#include <typeinfo>
// …
std::cout << typeid(fooParameter).name() << '\n';
Hope this helps!
I'm newish to C++ (but not new to programming in general)
I am trying to call this getOption, and the error message is complaining that this call:
getOption(
"What do you want to do?",
std::vector<std::string>[
"Add a person",
"Delete a person",
"Print database information",
"Report average age",
"List all names",
"Exit"]);
doesn't match the following function definition:
int getOption(std::string prompt, std::vector<std::string> choices)
I tried searching SO, but I don't really understand what is going on enough to come up with keywords that will match already answered questions.
What concept of C++ am I missing here?
You're just screwing up the constructor syntax. Don't use brackets; use braces. (This will only work in C++11.)
use braces instead. It's the initializer list in constructor. It only works in c++11.
I am using GTest to write UT for my code.
In order to test "non-virtual" functions, i generated the "function mangled name" using "nm" utility and added it in the "test suite.cpp" file (under extern "C") in the below format
__wrap_Mangled_name (function args as in original)
and then linked the same in "tst_def" file. Still when i run the test suite, the original function in the source code gets called instead of this "wrapped one". But in fact, this wrapped function should be called .
I cross-checked whether this mangled name is correct or not using "C++filt" utility and it was correct.
Any suggestions for this?
Thanks,
Udhai