code-generation

Generating code — is there an easy way to get a proper string representation of nullable type?

最后都变了- 提交于 2019-12-01 10:58:09
So I'm building an application that is going to do a ton of code generation with both C# and VB output (depending on project settings). I've got a CodeTemplateEngine, with two derived classes VBTemplateEngine and CSharpTemplateEngine. This question regards creating the property signatures based on columns in a database table. Using the IDataReader's GetSchemaTable method I gather the CLR type of the column, such as "System.Int32", and whether it IsNullable. However, I'd like to keep the code simple, and instead of having a property that looks like: public System.Int32? SomeIntegerColumn { get;

Axis2 generated Stubs are thread-safe?

瘦欲@ 提交于 2019-12-01 08:17:31
Are the Stubs generated by WSDL2JAVA (using XMLBeans binding option) through Axis2 1.5.4 thread-safe? Actually I have created one Stub for a Web Service that I am invoking through multiple threads. I have configured my own MultiThreadedHttpConnectionmanager and set the HTTPConstants.REUSE_HTTP_CLIENT as well but I am seeing some NullPointerExceptions in stub._getServiceClient().cleanupTransport that I call after each invocation. Sometimes the threads hang too. At the same time I noticed that in the generated Stub in the Web Service operation method, cleanup() is called already in the finally

Theory, examples of reversible parsers?

六月ゝ 毕业季﹏ 提交于 2019-12-01 07:39:31
Does anyone out there know about examples and the theory behind parsers that will take (maybe) an abstract syntax tree and produce code, instead of vice-versa. Mathematically, at least intuitively, I believe the function of code->AST is reversible, but I'm trying to find work/examples of this... besides the usual resources like the Dragon book and such. Any ideas? Such thing is called a Visitor. Is traverses the tree and does whatever has to be done, for example optimize or generate code. I rather like lewap's response: find a mathematical way to express a visitor and you have a dual to the

Viewing the code generated by @synthesize for getter/setter

守給你的承諾、 提交于 2019-12-01 06:08:26
Is it possible to view the exact code generated by @synthesize? You can read the Clang compiler source to see the C++ code that generates the getter and setter methods: http://llvm.org/svn/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp It's pretty cryptic but that's the most accurate way of seeing the code generated. You can also look at the objc_getProperty and objc_setProperty implementations in Apple's runtime implementation . While not literally the same as the code that is generated, this code is much easier to read and gives a clear indication of what a proper getter and setter should do.

Looking for a java code generation library [closed]

偶尔善良 提交于 2019-12-01 06:06:24
What is/are "good" java code generation libs? I found a generation part in JaxMe, but it's poor and old. I like to generate java code through java code. So basically use a lib to tell that it has to generate a certain concrete class or interface with X fields, Y methods, etc.. that are then written to the file system.. I know that frameworks use them, but can't find a standalone lib.. - Ed There are several libraries with various capabilities and ease of use: Javassist Apache BCEL ASM cglib You will probably have to take a look at the API of each one to determine which one is more suitable for

Automatically parsing PHP to separate PHP code from HTML

荒凉一梦 提交于 2019-12-01 05:56:34
I'm working on a large PHP code base; I'd like to separate the PHP code from the HTML and JavaScript. (I need to do several automatic search-and-replaces on the PHP code, and different ones on the HTML, and different on the JS). Is there a good parser engine that could separate out the PHP for me? I could do this using regular expressions, but they're not perfect. I could build something in ANTLR, perhaps, but a good already existing solution would be best. I should make clear: I don't want or need a full PHP parser. Just need to know if a given token is: - PHP code - PHP single quote string -

Emulating lambdas in C?

≡放荡痞女 提交于 2019-12-01 05:46:54
I should mention that I'm generating code in C, as opposed to doing this manually. I say this because it doesn't matter too much if there's a lot of code behind it, because the compiler should manage it all. Anyway, how would I go around emulating a lambda in C? I was thinking I could just generate a function with some random name somewhere in the source code and then call that? I'm not too sure. I haven't really tried anything just yet, since I wanted to get the idea down before I implement it. Is there some kind of preprocessor directive I can do, or some macro that will make this cleaner to

How to expose class functionality in GWT

给你一囗甜甜゛ 提交于 2019-12-01 05:38:41
问题 I have a class library written in Java and want to convert it to Javascript. All methods are pretty simple and mostly have to do with manipulating collections. I have this one class, GameControl, which I could instantiate and I want its methods exposed to other Javascript code on the page. I thought to use GWT. I have a running project in GWT which compiles, but I can't figure out how to expose my instance (+functionality) of the GameControl class. I thought using JSNI to expose my object

Why are unnecessary atomic loads not optimized away?

爷,独闯天下 提交于 2019-12-01 05:13:55
Let's consider this trivial code: #include <atomic> std::atomic<int> a; void f(){ for(int k=0;k<100;++k) a.load(std::memory_order_relaxed); } MSVC, Clang and GCC all perform 100 loads of a, while it seems obvious it could have been optimized away. I expected the function f to be a nop (See generated code here ) Actually, I expected this code generation for a volatile atomic: volatile std::atomic<int> va; void g(){ for(int k=0;k<100;++k) va.load(std::memory_order_relaxed); } Why do compilers not optimize away unnecessary atomic loads? 来源: https://stackoverflow.com/questions/56046501/why-are

C# Reflection, changing a method's body

走远了吗. 提交于 2019-12-01 04:48:11
问题 Is it possible to change the body of method during runtime? class Person { public void DoSth() { Console.WriteLine("Hello!"); } } I wanted to have a simple input field (like a textbox) where I can write the method body source code during runtime. The textbox may contain data like: for (int i = 0; i < 5; i++) Console.WriteLine(i); which should be excecuted when new Person().DoSth() is called. Is (or how is) this possible in C# (using Reflection)? Thanks for your help in advance. EDIT: If the