Java Reference
In-Depth Information
aged alternative to unmanaged function pointers). Built-in reference types include Object
(primary base class of all classes in the .NET Framework, which is the root of the type
hierarchy) and String .
Of course, a disadvantage of .NET is that it runs only on Windows platforms. One does
not get the \write once, run anywhere" exibility of Java.
8.5.2 Microsoft C# Compiler
When a C # program is fed to Microsoft's C # compiler, the compiler generates metadata,
CIL code describing the program. In order to achieve this, the compiler does multiple passes
over the code
In a first main pass, it looks for declarations in the code to gather information about the
used namespaces, classes, structs, enums, interfaces, delegates, methods, type parameters,
formal parameters, constructors, events, and attributes. All this information is extracted
over more sub-passes. A lexical analyzer identifies the tokens in the source file, and the parser
does a top-level parse, not going inside method bodies. Both the lexical analyzer and parser
are hand-written, the parser being a basic recursive-descent parser. Then, a \declaration"
pass records the locations of namespaces and type declarations in the program.
After the declaration pass, the compiler does not need to go over the actual program
code; it can do the next passes on the symbols it has generated so far to extract further
metadata. The next pass verifies that there are no cycles in the base types of the declared
types. A similar pass is also done for the generic parameter constraints on generic types,
verifying the acyclic hierarchy. After that, another pass checks the members (methods of
classes, elds of structs and enum values, etc.) of every type|for example, whether what
overriding methods override are actually virtual methods, or enums have no cycles, etc. One
last pass takes care of the values of all constant fields.
Then, the compiler generates CIL code. This time the compiler parses the method bodies
and determines the type of every expression within the method body. Many more sub-
passes follow this. The compiler does not need the actual program code once it has created
the annotated parse tree; subsequent passes work on this data structure, rewriting it as
necessary. The compiler transforms loops into gotos and labels. Then, more passes are done
to look for problems and to do some optimization. The compiler makes a pass for each of
the following:
To search for use of deprecated types and generate warnings if any exist,
To search for types that have no metadata yet and emit those,
To check whether expression trees 16 are constructed correctly,
To search for local variables that are defined but not used, and generate warnings,
To search for illegal patterns inside iterator blocks,
To search for unreachable code, such as a non-void method with no return statement,
and generate warnings,
To check whether every goto targets a sensible label, and every label is targeted by a
reachable goto, and
16 Expression trees are C # -specic tree-like data structures, where each node is an expression in the
code, for example, a method call or a binary operation such as x<y . For details on expression trees,
see [Microsoft, 2012].
 
Search WWH ::




Custom Search