compiler

Java: specific enums and generic Enum<?> parameters

Hi all, I want to pass any enum value to method in utility class and get another enum value of same enum type. Something like this: public class XMLUtils { public static Enum<?> getEnumAttribute(Element element, String name, Enum<?> defaultValue) { if (element.hasAttribute(name)) { String valueNam...

Generics in VB.NET

Now, as a C# programmer, I know that generics are awesome. However, when dabbling in some VB.NET, I discovered that the following does not cause a compiler error: Dim instance As List(Of Integer) instance.Add(True) Why is this? I know that you are not required to cast in VB.NET, but I'd have thought that this kills the main reason to...

Can I separate C++ main function and classes from Objective-C and/or C routines at compile and link?

I have a small C++ application which I imported Objective-C classes. It works as Objective-C++ files, .mm, but any C++ file that includes a header which may end up including some Objective-C header must be renamed to a .mm extension for the proper GCC drivers. Is there a way to write either a purely C++ wrapper for Objective-C classes ...

Is C++ built on top of C ?

Does C++ code gets converted to C before compilation ? ...

How can I modify the text of tokens in a CommonTokenStream with ANTLR?

I'm trying to learn ANTLR and at the same time use it for a current project. I've gotten to the point where I can run the lexer on a chunk of code and output it to a CommonTokenStream. This is working fine, and I've verified that the source text is being broken up into the appropriate tokens. Now, I would like to be able to modify the...

I'm attempting to write a .NET compiler using System.Reflection.Emit how do I do type resolution?

I've got a strategy for resolving types from referenced dlls. I'm stuck on trying to resolve types that are defined in the assembly that is being compiled. I'm using the System.Reflection.Emit apis with no 3rd party libraries. For instance: class A {} class B { public A AnInstanceOfA {get; private set;} } What's the best way to r...

How can I easily install arm-elf-gcc on OS X?

Please let me know if this should be on Server Fault... I've got some code I want to compile which requires arm-elf-gcc. I'm not an embedded programmer, so all this is new to me. My development machine is a Mac and I use fink pretty often, so I'd love to be able to install it that way. However, fink doesn't know of any package with that...

Problem with compiling a gwt project with ant

Hi, I've been using GWT for quite some time now and have only used the eclipse plugin to compile my projects so far. Due to a new requirement I need to use an ant build (for the first time) to build a gwt project. First I'll say that I have 2 modules which have an entry point and 2 other common modules which only contain java classes (wh...

var keyword isn't inferring the type of RepeaterItem, why is that?

Hey guys, This is a quick one. I have the following code: foreach (var item in myRepeater.Items) { MyViewModelItem x = new MyViewModelItem(); MapToEntity(x, item); myList.Add(report); } void MapToEntity(object entity, Control control); I expected this code to compile with no problems. It didn't, however. It resulted...

Auto-generating C++ code in a pre-build event using Visual Studio

I'm trying to use a pre-build event in Visual Studio (VS 2005 to be specific) to run a Python script which will automatically generate a .cpp file. The trouble I'm running into is that the compiler doesn't seem to know that this file is dirty and needs to be rebuilt until after the build has finished, which means that I need to build th...

Would it even make sense to write a C# compiler that targets LLVM?

I'm thinking about writing a small C# compiler. One idea I've been toying with is writing a subset of the C# grammar, say up to 2.0 for ANTLR. Then, using this to target the LLVM and write a native code compiler for C#? Does this idea even make sense or would this not work? Would there be any way to still make calls to the BCL? I ...

Generating Scala code trees from a Scala compiler plugin

There are a few resources on the web that are instructive in writing Scala compiler plugins that pattern-match against the code, but these don't help in generating code (constructing symbol trees). Where should I start to figure out how to do this? (If there's an easier way than to manually build symbol trees, I'd be interested as well.)...

Unable to recognize single line comments in Lex

Am learning lex in this process, I'm generating tokens for the C language, and am trying to recognize single line comments "//", but am having a conflict with the division operator [1-9][0-9]*|0x[0-9a-fA-F][0-9a-fA-F]* return NUMBER; [a-zA-Z][a-zA-Z0-9]* return IDENT; / ...

MSVC Object Layout Quirk

I have a simple class in C++ that has an integer and a vtable: class Something { virtual void sampleVirtualMethod(); int someInteger; }; If you look at the object layout for MSVC (using the /d1reportSingleClassLayout) you get: class Something size(8): +--- 0 | {vfptr} 4 | someInteger +--- W...

program that will compile in C but not in c++

this question was asked to my friend in an interview. "can you write any program that will compile in C but not in C++". is there any such program? ...

.NET compiler - CLR assembly metadata access / reflection from non-managed C++

I have a compiler that targets the .NET runtime (CLR). The current version of the compiler is written in standard C++ (non-managed). The compiler currently lacks support to reference assemblies at compile time, so the way I "import" .NET libraries is with a utility stub generator that is written in .NET, which reflects any assembly and e...

Character position in scanner using Lex/Flex

Hi there, In Lex/Flex is there a way to get the position in the character stream (from the start of the file) that a token appears at? Kind of like yylineno except that it returns the character position as an integer? If not, what's the best way to get at this? Do I need to keep my own counter? Thanks! ...

compiler: should I read entire file for scanning

Hi all, I am in the phase of scanning to build a compiler. I wonder if I should read entire file content before processing? I think it should be better since my compiler may need to do some optimization later (so I dont need to reread the file). But what if the input program is kinda big, it could take lots of memory to hold the file co...

"using typedef-name ... as class" on a forward declaration

I'm doing some policy-based designs here and I have the need to typedef lots of template types to shorten the names. Now the problem comes that when I need to use a pointer to one of those types I try to just forward-declare it but the compiler complains with a test.cpp:8: error: using typedef-name ‘Test1’ after ‘class’ It's nothing to ...

How do I address warnings when compiling SQLite with VC++?

Whenever I compile SQLite with Visual C++ 9 I get hundreds of warnings, such as potentially uninitialized variables conversion from wider integer types to narrower integer types signed/unsigned integers mismatches. I'm not alone - there's an SQLite FAQ question specifically about that. The answer to that question says that those wa...