code-generation

Theory, examples of reversible parsers?

一笑奈何 提交于 2019-12-19 08:56:47
问题 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? 回答1: Such thing is called a Visitor. Is traverses the tree and does whatever has to be done, for example optimize or generate code

Circular Buffer in Simulink

痴心易碎 提交于 2019-12-19 04:14:22
问题 I would like to implement a very huge (10^6 Elements - fixed size) circular buffer in pure Simulink model (no further toolboxes, no S-Function ). At some points I need to read some elements (anywhere, not just begin or end). The following solutions I can not use: "Queue Block" or "Buffer Block" (I have no Signal Processing Toolbox available) "Discrete Delay" ( I need a hugh buffer and will not place 10^6 delays into the model) "Sim Events" (I need to generate code from this model) The "S

How to configure StyleCop to suppress warnings on generated code?

被刻印的时光 ゝ 提交于 2019-12-19 02:54:04
问题 Another project, Visual Studio's Code Analysis has this option. But I couldn't find it for StyleCop (AKA Source Analysis). The file I want to ignore is a dbml's .designer.cs code, that includes the // <autogenerated> tag. A blog post tells me that it would be sufficient, but in my case it is not. 回答1: StyleCop: How To Ignore Generated Code Edit: Here is the header I use in generated grammars for ANTLR. This is actually the body of a StringTemplate template, so the two \> entries are actually

Generating all possible trees of depth N?

空扰寡人 提交于 2019-12-18 17:57:13
问题 I have several different types of tree nodes, each of which may have anywhere from 0 to 5 children. I'm trying to figure out an algorithm to generate all possible trees of depth <= N. Any help here? I'm having trouble figuring out how to recursively walk the tree given that each change I make to a node may expose new subtrees (or remove old ones). 回答1: Here's a Python program I wrote up that I think does what you're asking. It'll return all of the possible trees given a starting node.

How can I get PowerShell Added-Types to use Added Types

亡梦爱人 提交于 2019-12-18 17:15:22
问题 I'm working on a PoSh project that generates CSharp code, and then Add-Type s it into memory. The new types use existing types in an on disk DLL, which is loaded via Add-Type. All is well and good untill I actualy try to invoke methods on the new types. Here's an example of what I'm doing: $PWD = "." rm -Force $PWD\TestClassOne* $code = " namespace TEST{ public class TestClassOne { public int DoNothing() { return 1; } } }" $code | Out-File tcone.cs Add-Type -OutputAssembly $PWD\TestClassOne

likely(x) and __builtin_expect((x),1)

橙三吉。 提交于 2019-12-18 16:52:38
问题 I know the kernel uses the likely and unlikely macros prodigiously. The docs for the macros are located at Built-in Function: long __builtin_expect (long exp, long c). But they don't really discuss the details. How exactly does a compiler handle likely(x) and __builtin_expect((x),1) ? Is it handled by the code generator or the optimizer? Does it depend upon optimization levels? What's an example of the code generated? 回答1: I just tested a simple example on gcc. For x86 this seems to be

Programmatically writing Java [closed]

前提是你 提交于 2019-12-18 15:01:07
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I was wondering if there is already a library to programmatically write a java class or method? I am looking for libraries capable of writing new source code into existing files or extend files that already exist. 回答1: Look into Eclipse JDT. The Eclipse Java Development Tools (JDT) provide APIs to access and

Is it possible to modify a method body at run-time in .NET?

有些话、适合烂在心里 提交于 2019-12-18 14:54:52
问题 I know that it is possible (in theory) to create a new type at run-time, but is it possible to modify a method body of an existing type at run-time? My plan (if I can get this to work) is to tag up methods with a custom attribute, and then at run-time search for methods with the attribute, and insert some of my own code into the method body. Any suggestions? I suppose if I can't get that approach to work, I could always go with a virtual method in a base class (with the attributes), combined

Generate object model out of RelaxNG schema with RNGOM - how to start?

余生长醉 提交于 2019-12-18 13:26:38
问题 I want to generate an object model out of an RelaxNG Schema. Therefore I want to use the RNGOM Object Model/Parser (mainly because I could not find any alternative - although I don't even care about the language the parser is written in/generates). Now that I checked out the RNGOM source from SVN, I don't have ANY idea how to use RNGOM, since there is not any piece of information out there about the usage. A useful hint how to start with RNGOM - a link, example, or any description which saves

Adding custom attributes to C# classes using Roslyn

我们两清 提交于 2019-12-18 12:23:41
问题 Consider the following class in a file "MyClass.cs" using System; public class MyClass : Entity<long> { public long Id { get; set; } [Required] public string Name { get; set; } public string Slug { get; set; } public DateTime CreatedOn { get; private set; } public DateTime UpdatedOn { get; private set; } /* ... */ } Currently I manually create data contract classes looking as follows: [DataContract(Namespace = "http://example.com/", Name = "MyClass")] public sealed class MyClass { [DataMember