csdoc-patches Mailing List for C Sharp Document Generator (XML/HTML) (Page 4)
Status: Planning
Brought to you by:
mastergaurav
You can subscribe to this list here.
2003 |
Jan
|
Feb
(46) |
Mar
(17) |
Apr
(11) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(65) |
Nov
(17) |
Dec
|
From: <mas...@us...> - 2004-10-06 13:48:46
|
Update of /cvsroot/csdoc/CVSROOT In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25000 Modified Files: loginfo Log Message: Index: loginfo =================================================================== RCS file: /cvsroot/csdoc/CVSROOT/loginfo,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** loginfo 6 Oct 2004 13:41:21 -0000 1.3 --- loginfo 6 Oct 2004 13:42:01 -0000 1.4 *************** *** 27,29 **** CVSROOT /cvsroot/sitedocs/CVSROOT/syncmail %{sVv} mas...@us... ! ALL /cvsroot/sitedocs/CVSROOT/syncmail %{sVv} csd...@li... --- 27,29 ---- CVSROOT /cvsroot/sitedocs/CVSROOT/syncmail %{sVv} mas...@us... ! DEFAULT /cvsroot/sitedocs/CVSROOT/syncmail %{sVv} csd...@li... |
Update of /cvsroot/csdoc/csdoc/src/mcs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25921 Modified Files: .cvsignore AssemblyInfo.cs ChangeLog TODO assign.cs attribute.cs cfold.cs class.cs codegen.cs compiler.sln const.cs constant.cs convert.cs cs-parser.jay cs-tokenizer.cs decl.cs delegate.cs driver.cs ecore.cs enum.cs expression.cs flowanalysis.cs gen-treedump.cs iterators.cs literal.cs location.cs makefile mcs.exe.config modifiers.cs namespace.cs parameter.cs pending.cs report.cs rootcontext.cs statement.cs support.cs symbolwriter.cs tree.cs typemanager.cs Added Files: OTODO README compiler.csproj mcs.exe.sources Log Message: 2004-10-06 Gaurav Vaish <mastergaurav@> * Latest from Mono mcs --- NEW FILE: OTODO --- ---- This is a list of old tasks, just here for historical value ---- Open question: Create a toplevel block for anonymous methods? Anonymous Methods ----------------- Plan: * Resolve anonymous methods before. * Each time a Local matches, if the mode is `InAnonymous', flag the VariableInfo for `proxying'. * During Resolve track the depth required for local variables. * Before Emit, create proxy classes with proper depth. * Emit. Notes on memory allocation -------------------------- Outdated: A run of the AllocationProfile shows that the compiler allocates roughly 30 megabytes of strings. From those, 20 megabytes come from LookupType. See the notes on current_container problems below on memory usage. LookupTypeReflection: --------------------- With something like `System.Object', LookupTypeReflection will be called twice: once to find out that `System' is not a type and once for System.Object. This is required because System.Reflection requires that the type/nested types are not separated by a dot but by a plus sign. A nested class would be My+Class (My being the toplevel, Class the nested one). It is interesting to look at the most called lookups when bootstrapping MCS: 647 LTR: ArrayList 713 LTR: System.Globalization 822 LTR: System.Object+Expression 904 LTR: Mono.CSharp.ArrayList 976 LTR: System.Runtime.CompilerServices 999 LTR: Type 1118 LTR: System.Runtime 1208 LTR: Mono.CSharp.Type 1373 LTR: Mono.Languages 1599 LTR: System.Diagnostics 2036 LTR: System.Text 2302 LTR: System.Reflection.Emit 2515 LTR: System.Collections 4527 LTR: System.Reflection 22273 LTR: Mono.CSharp 24245 LTR: System 27005 LTR: Mono Analysis: The top 9 lookups are done for things which are not types. Mono.CSharp.Type happens to be a common lookup: the class Type used heavily in the compiler in the default namespace. RED FLAG: Then `Type' is looked up alone a lot of the time, this happens in parameter declarations and am not entirely sure that this is correct (FindType will pass to LookupInterfaceOrClass a the current_type.FullName, which for some reason is null!). This seems to be a problem with a lost piece of context during FindType. System.Object is also used a lot as a toplevel class, and we assume it will have children, we should just shortcut this. A cache: Adding a cache and adding a catch for `System.Object' to flag that it wont be the root of a hierarchy reduced the MCS bootstrap time from 10.22 seconds to 8.90 seconds. This cache is currently enabled with SIMPLE_SPEEDUP in typemanager.cs. Memory consumption went down from 74 megs to 65 megs with this change. Major tasks: ------------ Pinned and volatile require type modifiers that can not be encoded with Reflection.Emit. * Revisit Primary-expression, as it has now been split into non-array-creation-expression and array-creation-expression. * Emit `pinned' for pinned local variables. Both `modreq' and pinned will require special hacks in the compiler. * Make sure that we are pinning the right variable * local_variable_declaration Not sure that this grammar is correct, we might have to resolve this during semantic analysis. * Optimizations In Indexers and Properties, probably support an EmitWithDup That emits the code to call Get and then leaves a this pointer in the stack, so that later a Store can be emitted using that this pointer (consider Property++ or Indexer++) * Use of local temporary in UnaryMutator We should get rid of the Localtemporary there for some cases This turns out to be very complex, at least for the post-version, because this case: a = i++ To produce optimal code, it is necessary for UnaryMutator to know that it is being assigned to a variable (the way the stack is laid out using dup requires the store to happen inside UnaryMutator). * Interface indexers I have not figured out why the Microsoft version puts an `instance' attribute, and I am not generating this `instance' attribute. Explanation: The reason for the `instance' attribute on indexers is that indexers only apply to instances * Check for Final when overriding, if the parent is Final, then we cant allow an override. Implement base indexer access. current_container/current_namespace and the DeclSpace ----------------------------------------------------- We are storing fully qualified names in the DeclSpace instead of the node, this is because `current_namespace' (Namepsace) is not a DeclSpace like `current_container'. The reason for storing the full names today is this: namespace X { class Y { } } namespace A { class Y { } } The problem is that we only use the namespace stack to track the "prefix" for typecontainers, but they are not typecontainers themselves, so we have to use fully qualified names, because both A.X and A.Y would be entered in the toplevel type container. If we use the short names, there would be a name clash. To fix this problem, we have to make namespaces DeclSpaces. The full size, contrasted with the size that could be stored is: corlib: Size of strings held: 368901 Size of strings short: 147863 System: Size of strings held: 212677 Size of strings short: 97521 System.XML: Size of strings held: 128055 Size of strings short: 35782 System.Data: Size of strings held: 117896 Size of strings short: 36153 System.Web: Size of strings held: 194527 Size of strings short: 58064 System.Windows.Forms: Size of strings held: 220495 Size of strings short: 64923 The use of DottedName --------------------- We could probably use a different system to represent names, like this: class Name { string simplename; Name parent; } So `System.ComponentModel' becomes: x: (System, null) y: (ComponentModel, x) The problem is that we would still need to construct the name to pass to GetType. This has been now implemented, its called "QualifiedIdentifier" TODO: 1. Create a "partial" emit context for each TypeContainer.. 2. EmitContext should be partially constructed. No IL Generator. interface_type review. parameter_array, line 952: `note: must be a single dimension array type'. Validate this Instance idea ------------- It would be nice to have things that can be "instances" to have an EmitInstance method (this would default to nothing). The idea is to be able to use efficiently the instance data on stack manipulations, as opposed to the current scheme, where we basically have a few special cases. * `yield' is no longer a keyword, it only has special meaning before a return or break keywords. * Study side effects with assign * Study TemporaryStorage/LocalStorage -> Merge/rename --- NEW FILE: README --- These are the sources to the Mono C# compiler --------------------------------------------- Read the mcs/docs/compiler.txt for an overview of the compiler. Testing the Compiler -------------------- You might want to use the `make btest' in this directory to have the compiler bootstrap itself, this is the basic regression test. Before commiting changes to MCS, make sure that all the tests in `mcs/tests' pass, and all the tests in 'mcs/errors' have the expected result, type: cd mcs # The top-level 'mcs' directory make compiler-tests If you want to test the installed compiler, you can run: cd mcs # The top-level 'mcs' directory make test-installed-compiler Full Bootstrap ============== To finally ensure the state of the compiler, it is ideal to do a full bootstrap, to do this, do: cd mcs make clean; make make install That installs the compiler and assemblies compiled by the new compiler. Then, repeat that step again: make clean make If things work, the compiler has not added a new regression while building the mscorlib and the compiler itself. Tests ===== When bugs are fixed, new tests must be added to the `mcs/tests' directory to excercise the problem and to guarantee that we keep the compiler in a good state. When an error is reported, it should be added to mcs/errors. We try to make the errors numbers be the same as the ones in Microsoft C#, if this is not possible, allocate a negative error number, and list it in mcs/errors/errors.txt --- NEW FILE: compiler.csproj --- <VisualStudioProject> <CSHARP ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{896D1461-B76B-41C0-ABE6-ACA2BB4F7B5A}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "mcs" AssemblyOriginatorKeyFile = "" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Exe" PreBuildEvent = "" PostBuildEvent = "" RootNamespace = "CIR" RunPostBuildEvent = "OnBuildSuccess" StartupObject = "" > <Config Name = "Debug" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "DEBUG;TRACE" DocumentationFile = "" DebugSymbols = "true" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "false" OutputPath = ".\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> <Config Name = "Release" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "TRACE" DocumentationFile = "" DebugSymbols = "false" FileAlignment = "4096" IncrementalBuild = "true" NoStdLib = "false" NoWarn = "" Optimize = "true" OutputPath = "bin\Release\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" /> </References> </Build> <Files> <Include> <File RelPath = "anonymous.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "AssemblyInfo.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "assign.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "attribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "cfold.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "class.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "codegen.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "const.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "constant.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "convert.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CryptoConvert.cs" Link = "..\class\corlib\Mono.Security.Cryptography\CryptoConvert.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "cs-parser.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "cs-tokenizer.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "decl.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "delegate.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "driver.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "ecore.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "enum.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "expression.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "flowanalysis.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "iterators.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "literal.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "location.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "modifiers.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "MonoSymbolFile.cs" Link = "..\class\Mono.CSharp.Debugger\MonoSymbolFile.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "MonoSymbolTable.cs" Link = "..\class\Mono.CSharp.Debugger\MonoSymbolTable.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "MonoSymbolWriter.cs" Link = "..\class\Mono.CSharp.Debugger\MonoSymbolWriter.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "namespace.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "parameter.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "pending.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "report.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "rootcontext.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "statement.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "support.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "symbolwriter.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "tree.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "typemanager.cs" SubType = "Code" BuildAction = "Compile" /> <Folder RelPath = "Web References\" WebReferences = "TRUE" /> </Include> </Files> </CSHARP> </VisualStudioProject> --- NEW FILE: mcs.exe.sources --- AssemblyInfo.cs anonymous.cs assign.cs attribute.cs driver.cs cs-tokenizer.cs cfold.cs class.cs codegen.cs const.cs constant.cs convert.cs decl.cs delegate.cs enum.cs ecore.cs expression.cs flowanalysis.cs iterators.cs literal.cs location.cs modifiers.cs namespace.cs parameter.cs pending.cs report.cs rootcontext.cs statement.cs support.cs typemanager.cs symbolwriter.cs tree.cs ../class/Mono.CSharp.Debugger/MonoSymbolFile.cs ../class/Mono.CSharp.Debugger/MonoSymbolTable.cs ../class/Mono.CSharp.Debugger/MonoSymbolWriter.cs ../class/corlib/Mono.Security.Cryptography/CryptoConvert.cs Index: .cvsignore =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/mcs/.cvsignore,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** .cvsignore 16 Sep 2003 13:00:19 -0000 1.2 --- .cvsignore 6 Oct 2004 13:46:43 -0000 1.3 *************** *** 1,15 **** ! compiler.pdb ! compiler.exe ! compiler.suo ! compiler.csproj ! compiler.csproj.user ! cs-parser.cs ! y.output *.pdb - mcs.exe - mcsdoc.exe Web References - bin - obj Web References Web References --- 1,16 ---- ! *.mdb *.pdb Web References Web References Web References + bin + compiler.csproj + compiler.csproj.user + compiler.exe + compiler.pdb + compiler.suo + cs-parser.cs + mcs + obj + semantic.cache + y.output Index: AssemblyInfo.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/mcs/AssemblyInfo.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AssemblyInfo.cs 16 Sep 2003 13:00:19 -0000 1.2 --- AssemblyInfo.cs 6 Oct 2004 13:46:43 -0000 1.3 *************** *** 2,6 **** using System.Runtime.CompilerServices; ! [assembly: AssemblyVersion("0.27")] [assembly: AssemblyTitle ("Mono C# Compiler")] [assembly: AssemblyDescription ("Mono C# Compiler")] --- 2,6 ---- using System.Runtime.CompilerServices; ! [assembly: AssemblyVersion("1.1.1")] [assembly: AssemblyTitle ("Mono C# Compiler")] [assembly: AssemblyDescription ("Mono C# Compiler")] Index: ChangeLog =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/mcs/ChangeLog,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ChangeLog 16 Sep 2003 13:00:20 -0000 1.2 --- ChangeLog 6 Oct 2004 13:46:43 -0000 1.3 *************** *** 1,2 **** --- 1,4158 ---- + 2004-10-04 Miguel de Icaza <mi...@xi...> + + * ecore.cs (Expression.Constantity): Add support for turning null + into a constant. + + * const.cs (Const.Define): Allow constants to be reference types + as long as the value is Null. + + 2004-10-04 Juraj Skripsky <js...@ho...> [...7025 lines suppressed...] --- 16561,16565 ---- enum_body or enum_member_declarations so we can handle trailing commas on enumeration members. Gets rid of a shift/reduce. ! (type_list): Need a COMMA in the middle. *************** *** 12418,12422 **** * cs-parser.jay: Add precendence rules for a number of operators ot reduce the number of shift/reduce conflicts in the grammar. ! 2001-07-17 Miguel de Icaza <mi...@xi...> --- 16574,16578 ---- * cs-parser.jay: Add precendence rules for a number of operators ot reduce the number of shift/reduce conflicts in the grammar. ! 2001-07-17 Miguel de Icaza <mi...@xi...> Index: TODO =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/mcs/TODO,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TODO 16 Sep 2003 13:00:22 -0000 1.2 --- TODO 6 Oct 2004 13:46:44 -0000 1.3 *************** *** 1,20 **** ! Iterators --------- ! * Fix simple case (foreach) ! * Study side effects with assign ! * Study TemporaryStorage/LocalStorage -> Merge/rename ! Big issues: try/finally in iterators. ! Instance idea ! ------------- ! It would be nice to have things that can be "instances" to have an ! EmitInstance method (this would default to nothing). ! The idea is to be able to use efficiently the instance data on stack ! manipulations, as opposed to the current scheme, where we basically have ! a few special cases. Optimization ideas --- 1,51 ---- ! NEW NOTES: ! ---------- ! ! ImplicitStandardConversionExists and ImplicitStandardConversion ! should always be the same, but there are a few diverging lines that ! must be studied: ! ! if (expr_type == target_type && !(expr is NullLiteral)) ! return expr; ! ! vs: ! ! if (expr_type == target_type) ! return true; ! ! ! Null Type --------- ! Need to introduce the NullType concept into the compiler, to address a ! few small buglets and remove the hardcoded values for NullLiteral. ! NullLiteral will be the only expression that has the NullType as its type. ! This is what must be used to test for Null literals, instead of `is NullLiteral', ! and this will introduce a couple of fixes to the rules. ! Revert Martin's patch to Conditional expression that worked around this bug: ! Reference r = xx ? null : null ! ! The right fix is to introduce NullType ! ! **************************************************************************************** ! * ! * The information on the rest of this file is mostly outdated, and its kept here for ! * historical reasons ! * ! **************************************************************************************** ! ! Error Reporting: ! ---------------- ! ! * Make yyerror show a nice syntax error, instead of the current mess. ! ! Iterators ! --------- ! ! * Reset should throw not implemented now. Optimization ideas *************** *** 43,66 **** - Anonymous Methods - ----------------- - - Plan: - - * Resolve anonymous methods before. - * Each time a Local matches, if the mode is `InAnonymous', flag - the VariableInfo for `proxying'. - * During Resolve track the depth required for local variables. - * Before Emit, create proxy classes with proper depth. - * Emit. - - Return Type: - During Resolve, track all the return types. - Allow for ec.ReturnType to be null, indicating `Pending Return Evaluation' - - - Open question: - Create a toplevel block for anonymous methods? - EmitContext.ResolveTypeTree --------------------------- --- 74,77 ---- *************** *** 101,170 **** that we could use for this. - Notes on memory allocation - -------------------------- - - A run of the AllocationProfile shows that the compiler allocates roughly - 30 megabytes of strings. From those, 20 megabytes come from - LookupType. - - See the notes on current_container problems below on memory usage. - - LookupTypeReflection: - --------------------- - - With something like `System.Object', LookupTypeReflection will be called - twice: once to find out that `System' is not a type and once - for System.Object. - - This is required because System.Reflection requires that the type/nested types are - not separated by a dot but by a plus sign. - - A nested class would be My+Class (My being the toplevel, Class the nested one). - - It is interesting to look at the most called lookups when bootstrapping MCS: - - 647 LTR: ArrayList - 713 LTR: System.Globalization - 822 LTR: System.Object+Expression - 904 LTR: Mono.CSharp.ArrayList - 976 LTR: System.Runtime.CompilerServices - 999 LTR: Type - 1118 LTR: System.Runtime - 1208 LTR: Mono.CSharp.Type - 1373 LTR: Mono.Languages - 1599 LTR: System.Diagnostics - 2036 LTR: System.Text - 2302 LTR: System.Reflection.Emit - 2515 LTR: System.Collections - 4527 LTR: System.Reflection - 22273 LTR: Mono.CSharp - 24245 LTR: System - 27005 LTR: Mono - - Analysis: - The top 9 lookups are done for things which are not types. - - Mono.CSharp.Type happens to be a common lookup: the class Type - used heavily in the compiler in the default namespace. - - RED FLAG: - - Then `Type' is looked up alone a lot of the time, this happens - in parameter declarations and am not entirely sure that this is - correct (FindType will pass to LookupInterfaceOrClass a the current_type.FullName, - which for some reason is null!). This seems to be a problem with a lost - piece of context during FindType. - - System.Object is also used a lot as a toplevel class, and we assume it will - have children, we should just shortcut this. - - A cache: - - Adding a cache and adding a catch for `System.Object' to flag that it wont be the - root of a hierarchy reduced the MCS bootstrap time from 10.22 seconds to 8.90 seconds. - - This cache is currently enabled with SIMPLE_SPEEDUP in typemanager.cs. Memory consumption - went down from 74 megs to 65 megs with this change. - Ideas: ------ --- 112,115 ---- *************** *** 173,257 **** we should just make it simple for a probe to know that there is no need for it. - The use of DottedName - --------------------- - - We could probably use a different system to represent names, like this: - - class Name { - string simplename; - Name parent; - } - - So `System.ComponentModel' becomes: - - x: (System, null) - y: (ComponentModel, x) - - The problem is that we would still need to construct the name to pass to - GetType. - - current_container/current_namespace and the DeclSpace - ----------------------------------------------------- - - We are storing fully qualified names in the DeclSpace instead of the node, - this is because `current_namespace' (Namepsace) is not a DeclSpace like - `current_container'. - - The reason for storing the full names today is this: - - namespace X { - class Y { - } - } - - namespace A { - class Y { - } - } - - The problem is that we only use the namespace stack to track the "prefix" - for typecontainers, but they are not typecontainers themselves, so we have - to use fully qualified names, because both A.X and A.Y would be entered - in the toplevel type container. If we use the short names, there would be - a name clash. - - To fix this problem, we have to make namespaces DeclSpaces. - - The full size, contrasted with the size that could be stored is: - corlib: - Size of strings held: 368901 - Size of strings short: 147863 - - System: - Size of strings held: 212677 - Size of strings short: 97521 - - System.XML: - Size of strings held: 128055 - Size of strings short: 35782 - - System.Data: - Size of strings held: 117896 - Size of strings short: 36153 - - System.Web: - Size of strings held: 194527 - Size of strings short: 58064 - - System.Windows.Forms: - Size of strings held: 220495 - Size of strings short: 64923 - - - TODO: - - 1. Create a "partial" emit context for each TypeContainer.. - - 2. EmitContext should be partially constructed. No IL Generator. - - interface_type review. - - parameter_array, line 952: `note: must be a single dimension array type'. Validate this - Dead Code Elimination bugs: --------------------------- --- 118,121 ---- *************** *** 261,272 **** Major tasks: ------------ - - Pinned and volatile require type modifiers that can not be encoded - with Reflection.Emit. - Properties and 17.6.3: Finish it. - Implement base indexer access. - readonly variables and ref/out --- 125,130 ---- *************** *** 274,288 **** ---- - * Check for Final when overriding, if the parent is Final, then we cant - allow an override. - - * Interface indexers - - I have not figured out why the Microsoft version puts an - `instance' attribute, and I am not generating this `instance' attribute. - - Explanation: The reason for the `instance' attribute on - indexers is that indexers only apply to instances - * Break/Continue statements --- 132,135 ---- *************** *** 316,324 **** * Merge test 89 and test-34 - * Revisit - - Primary-expression, as it has now been split into - non-array-creation-expression and array-creation-expression. - * Code cleanup --- 163,166 ---- *************** *** 330,339 **** Handle modreq from public apis. - * Emit `pinned' for pinned local variables. - - Both `modreq' and pinned will require special hacks in the compiler. - - * Make sure that we are pinning the right variable - * Merge tree.cs, rootcontext.cs --- 172,175 ---- *************** *** 359,375 **** is on TypeContainer, and probably should go in DeclSpace. - * Use of local temporary in UnaryMutator - - We should get rid of the Localtemporary there for some cases - - This turns out to be very complex, at least for the post-version, - because this case: - - a = i++ - - To produce optimal code, it is necessary for UnaryMutator to know - that it is being assigned to a variable (the way the stack is laid - out using dup requires the store to happen inside UnaryMutator). - * Tests --- 195,198 ---- *************** *** 377,387 **** test for all the numeric conversions. - * Optimizations - - In Indexers and Properties, probably support an EmitWithDup - That emits the code to call Get and then leaves a this pointer - in the stack, so that later a Store can be emitted using that - this pointer (consider Property++ or Indexer++) - * Optimizations: variable allocation. --- 200,203 ---- *************** *** 422,428 **** { oob_stack.Push (lexer.Location) } takes a "slot" in the productions. - * local_variable_declaration - - Not sure that this grammar is correct, we might have to - resolve this during semantic analysis. --- 238,240 ---- Index: assign.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/mcs/assign.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** assign.cs 16 Sep 2003 13:00:22 -0000 1.2 --- assign.cs 6 Oct 2004 13:46:44 -0000 1.3 *************** *** 30,46 **** public interface IAssignMethod { // ! // This method will emit the code for the actual assignment ! // ! void EmitAssign (EmitContext ec, Expression source); ! // ! // This method is invoked before any code generation takes ! // place, and it is a mechanism to inform that the expression ! // will be invoked more than once, and that the method should ! // use temporary values to avoid having side effects // ! // Example: a [ g () ] ++ // ! void CacheTemporaries (EmitContext ec); } --- 30,152 ---- public interface IAssignMethod { // ! // This is an extra version of Emit. If leave_copy is `true' ! // A copy of the expression will be left on the stack at the ! // end of the code generated for EmitAssign // ! void Emit (EmitContext ec, bool leave_copy); ! // ! // This method does the assignment ! // `source' will be stored into the location specified by `this' ! // if `leave_copy' is true, a copy of `source' will be left on the stack ! // if `prepare_for_load' is true, when `source' is emitted, there will ! // be data on the stack that it can use to compuatate its value. This is ! // for expressions like a [f ()] ++, where you can't call `f ()' twice. // ! void EmitAssign (EmitContext ec, Expression source, bool leave_copy, bool prepare_for_load); ! ! /* ! For simple assignments, this interface is very simple, EmitAssign is called with source ! as the source expression and leave_copy and prepare_for_load false. ! ! For compound assignments it gets complicated. ! ! EmitAssign will be called as before, however, prepare_for_load will be ! true. The @source expression will contain an expression ! which calls Emit. So, the calls look like: ! ! this.EmitAssign (ec, source, false, true) -> ! source.Emit (ec); -> ! [...] -> ! this.Emit (ec, false); -> ! end this.Emit (ec, false); -> ! end [...] ! end source.Emit (ec); ! end this.EmitAssign (ec, source, false, true) ! ! ! When prepare_for_load is true, EmitAssign emits a `token' on the stack that ! Emit will use for its state. ! ! Let's take FieldExpr as an example. assume we are emitting f ().y += 1; ! ! Here is the call tree again. This time, each call is annotated with the IL ! it produces: ! ! this.EmitAssign (ec, source, false, true) ! call f ! dup ! ! Binary.Emit () ! this.Emit (ec, false); ! ldfld y ! end this.Emit (ec, false); ! ! IntConstant.Emit () ! ldc.i4.1 ! end IntConstant.Emit ! ! add ! end Binary.Emit () ! ! stfld ! end this.EmitAssign (ec, source, false, true) ! ! Observe two things: ! 1) EmitAssign left a token on the stack. It was the result of f (). ! 2) This token was used by Emit ! ! leave_copy (in both EmitAssign and Emit) tells the compiler to leave a copy ! of the expression at that point in evaluation. This is used for pre/post inc/dec ! and for a = x += y. Let's do the above example with leave_copy true in EmitAssign ! ! this.EmitAssign (ec, source, true, true) ! call f ! dup ! ! Binary.Emit () ! this.Emit (ec, false); ! ldfld y ! end this.Emit (ec, false); ! ! IntConstant.Emit () ! ldc.i4.1 ! end IntConstant.Emit ! ! add ! end Binary.Emit () ! ! dup ! stloc temp ! stfld ! ldloc temp ! end this.EmitAssign (ec, source, true, true) ! ! And with it true in Emit ! ! this.EmitAssign (ec, source, false, true) ! call f ! dup ! ! Binary.Emit () ! this.Emit (ec, true); ! ldfld y ! dup ! stloc temp ! end this.Emit (ec, true); ! ! IntConstant.Emit () ! ldc.i4.1 ! end IntConstant.Emit ! ! add ! end Binary.Emit () ! ! stfld ! ldloc temp ! end this.EmitAssign (ec, source, false, true) ! ! Note that these two examples are what happens for ++x and x++, respectively. ! */ } *************** *** 56,77 **** /// basically it creates a local variable, and its emit instruction generates /// code to access this value, return its address or save its value. /// </remarks> public class LocalTemporary : Expression, IMemoryLocation { LocalBuilder builder; ! public LocalTemporary (EmitContext ec, Type t) { type = t; eclass = ExprClass.Value; loc = Location.Null; ! builder = ec.GetTemporaryLocal (t); } - public void Release (EmitContext ec) - { - ec.FreeTemporaryLocal (builder, type); - builder = null; - } - public LocalTemporary (LocalBuilder b, Type t) { --- 162,193 ---- /// basically it creates a local variable, and its emit instruction generates /// code to access this value, return its address or save its value. + /// + /// If `is_address' is true, then the value that we store is the address to the + /// real value, and not the value itself. + /// + /// This is needed for a value type, because otherwise you just end up making a + /// copy of the value on the stack and modifying it. You really need a pointer + /// to the origional value so that you can modify it in that location. This + /// Does not happen with a class because a class is a pointer -- so you always + /// get the indirection. + /// + /// The `is_address' stuff is really just a hack. We need to come up with a better + /// way to handle it. /// </remarks> public class LocalTemporary : Expression, IMemoryLocation { LocalBuilder builder; + bool is_address; ! public LocalTemporary (EmitContext ec, Type t) : this (ec, t, false) {} ! ! public LocalTemporary (EmitContext ec, Type t, bool is_address) { type = t; eclass = ExprClass.Value; loc = Location.Null; ! builder = ec.GetTemporaryLocal (is_address ? TypeManager.GetReferenceType (t): t); ! this.is_address = is_address; } public LocalTemporary (LocalBuilder b, Type t) { *************** *** 81,84 **** --- 197,206 ---- builder = b; } + + public void Release (EmitContext ec) + { + ec.FreeTemporaryLocal (builder, type); + builder = null; + } public override Expression DoResolve (EmitContext ec) *************** *** 89,103 **** public override void Emit (EmitContext ec) { ! ec.ig.Emit (OpCodes.Ldloc, builder); } public void Store (EmitContext ec) { ! ec.ig.Emit (OpCodes.Stloc, builder); } public void AddressOf (EmitContext ec, AddressOp mode) { ! ec.ig.Emit (OpCodes.Ldloca, builder); } } --- 211,247 ---- public override void Emit (EmitContext ec) { ! ILGenerator ig = ec.ig; ! ! ig.Emit (OpCodes.Ldloc, builder); ! // we need to copy from the pointer ! if (is_address) ! LoadFromPtr (ig, type); } + // NB: if you have `is_address' on the stack there must + // be a managed pointer. Otherwise, it is the type from + // the ctor. public void Store (EmitContext ec) { ! ILGenerator ig = ec.ig; ! ig.Emit (OpCodes.Stloc, builder); } public void AddressOf (EmitContext ec, AddressOp mode) { ! // if is_address, than this is just the address anyways, ! // so we just return this. ! ILGenerator ig = ec.ig; ! ! if (is_address) ! ig.Emit (OpCodes.Ldloc, builder); ! else ! ig.Emit (OpCodes.Ldloca, builder); ! } ! ! public bool PointsToAddress { ! get { ! return is_address; ! } } } *************** *** 261,271 **** if ((source.eclass == ExprClass.Type) && (source is TypeExpr)) { ! source.Error_UnexpectedKind ("variable or value"); return null; ! } else if (source is MethodGroupExpr){ ((MethodGroupExpr) source).ReportUsageError (); return null; - } if (target_type == source_type) return this; --- 405,417 ---- if ((source.eclass == ExprClass.Type) && (source is TypeExpr)) { ! source.Error_UnexpectedKind ("variable or value", loc); return null; ! } else if ((RootContext.Version == LanguageVersion.ISO_1) && ! (source is MethodGroupExpr)){ ((MethodGroupExpr) source).ReportUsageError (); return null; + } + if (target_type == source_type) return this; *************** *** 295,308 **** // // 2. and the original right side is implicitly convertible to ! // the type of target_type. // if (Convert.ImplicitStandardConversionExists (a.original_source, target_type)) return this; Convert.Error_CannotImplicitConversion (loc, a.original_source.Type, target_type); return null; } } ! source = Convert.ImplicitConversionRequired (ec, source, target_type, loc); if (source == null) --- 441,462 ---- // // 2. and the original right side is implicitly convertible to ! // the type of target // if (Convert.ImplicitStandardConversionExists (a.original_source, target_type)) return this; + // + // In the spec 2.4 they added: or if type of the target is int + // and the operator is a shift operator... + // + if (source_type == TypeManager.int32_type && + (b.Oper == Binary.Operator.LeftShift || b.Oper == Binary.Operator.RightShift)) + return this; + Convert.Error_CannotImplicitConversion (loc, a.original_source.Type, target_type); return null; } } ! source = Convert.ImplicitConversionRequired (ec, source, target_type, loc); if (source == null) *************** *** 348,352 **** Expression temp_source = (temp != null) ? temp : source; ! ((IAssignMethod) target).EmitAssign (ec, temp_source); return temp_source; } --- 502,506 ---- Expression temp_source = (temp != null) ? temp : source; ! ((IAssignMethod) target).EmitAssign (ec, temp_source, false, false); return temp_source; } *************** *** 370,389 **** return; } - - bool use_temporaries = false; - // - // FIXME! We need a way to "probe" if the process can - // just use `dup' to propagate the result - // IAssignMethod am = (IAssignMethod) target; - - if (this is CompoundAssign){ - am.CacheTemporaries (ec); - use_temporaries = true; - } - - if (!is_statement) - use_temporaries = true; Expression temp_source; --- 524,529 ---- *************** *** 398,422 **** } else temp_source = source; ! ! if (use_temporaries){ ! // ! // Doing this for every path is too expensive ! // I wonder if we can work around this and have a less ! // expensive path ! // ! LocalTemporary tempo; ! ! tempo = new LocalTemporary (ec, source.Type); ! ! temp_source.Emit (ec); ! tempo.Store (ec); ! am.EmitAssign (ec, tempo); ! if (!is_statement) ! tempo.Emit (ec); ! ! tempo.Release (ec); ! } else { ! am.EmitAssign (ec, temp_source); ! } if (embedded != null) { --- 538,543 ---- } else temp_source = source; ! ! am.EmitAssign (ec, temp_source, !is_statement, this is CompoundAssign); if (embedded != null) { Index: attribute.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/mcs/attribute.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** attribute.cs 16 Sep 2003 13:00:23 -0000 1.2 --- attribute.cs 6 Oct 2004 13:46:44 -0000 1.3 *************** *** 1,1146 **** ! // ! // attribute.cs: Attribute Handler ! // ! // Author: Ravi Pratap (ra...@xi...) ! // ! // Licensed under the terms of the GNU GPL ! // ! // (C) 2001 Ximian, Inc (http://www.ximian.com) ! // ! // [...2565 lines suppressed...] ! if (excluded != null) ! return excluded == TRUE ? true : false; ! ! ConditionalAttribute[] attrs = mb.GetCustomAttributes (TypeManager.conditional_attribute_type, true) as ConditionalAttribute[]; ! if (attrs.Length == 0) { ! analyzed_method_excluded.Add (mb, FALSE); ! return false; ! } ! ! foreach (ConditionalAttribute a in attrs) { ! if (RootContext.AllDefines.Contains (a.ConditionString)) { ! analyzed_method_excluded.Add (mb, FALSE); ! return false; ! } ! } ! analyzed_method_excluded.Add (mb, TRUE); ! return true; ! } ! } ! } Index: cfold.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/mcs/cfold.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** cfold.cs 16 Sep 2003 13:00:23 -0000 1.2 --- cfold.cs 6 Oct 2004 13:46:44 -0000 1.3 *************** *** 60,73 **** --- 60,79 ---- // operand is of type sbyte, short, int or long // + #if WRONG Constant match, other; + #endif if (left is ULongConstant){ + #if WRONG other = right; match = left; + #endif if (!(right is ULongConstant)) right = right.ToULong (loc); } else { + #if WRONG other = left; match = right; + #endif left = left.ToULong (loc); } *************** *** 99,110 **** // converted to type long. // ! Constant match, other; ! if (left is UIntConstant){ other = right; ! match = left; ! } else { other = left; - match = right; - } // Nothing to do. --- 105,113 ---- // converted to type long. // ! Constant other; ! if (left is UIntConstant) other = right; ! else other = left; // Nothing to do. *************** *** 112,119 **** return; ! if (other is SByteConstant || other is ShortConstant || ! other is IntConstant){ left = left.ToLong (loc); right = right.ToLong (loc); } --- 115,135 ---- return; ! IntConstant ic = other as IntConstant; ! if (ic != null){ ! if (ic.Value >= 0){ ! if (left == other) ! left = new UIntConstant ((uint) ic.Value); ! else ! right = new UIntConstant ((uint) ic.Value); ! return; ! } ! } ! ! if (other is SByteConstant || other is ShortConstant || ic != null){ left = left.ToLong (loc); right = right.ToLong (loc); + } else { + left = left.ToUInt (loc); + right = left.ToUInt (loc); } *************** *** 181,185 **** Type result_type = null; bool bool_res; ! // // Enumerator folding --- 197,201 ---- Type result_type = null; bool bool_res; ! // // Enumerator folding *************** *** 955,958 **** --- 971,987 ---- } + if (left is NullLiteral){ + if (right is NullLiteral) + return new BoolConstant (true); + else if (right is StringConstant) + return new BoolConstant ( + ((StringConstant) right).Value == null); + } else if (right is NullLiteral){ + if (left is NullLiteral) + return new BoolConstant (true); + else if (left is StringConstant) + return new BoolConstant ( + ((StringConstant) left).Value == null); + } if (left is StringConstant && right is StringConstant){ return new BoolConstant ( *************** *** 961,965 **** } ! DoConstantNumericPromotions (ec, oper, ref left, ref right, loc); if (left == null || right == null) --- 990,994 ---- } ! DoConstantNumericPromotions (ec, oper, ref left, ref right, loc); if (left == null || right == null) *************** *** 996,999 **** --- 1025,1041 ---- ((BoolConstant) right).Value); } + if (left is NullLiteral){ + if (right is NullLiteral) + return new BoolConstant (false); + else if (right is StringConstant) + return new BoolConstant ( + ((StringConstant) right).Value != null); + } else if (right is NullLiteral){ + if (left is NullLiteral) + return new BoolConstant (false); + else if (left is StringConstant) + return new BoolConstant ( + ((StringConstant) left).Value != null); + } if (left is StringConstant && right is StringConstant){ return new BoolConstant ( Index: class.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/mcs/class.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** class.cs 16 Sep 2003 13:00:24 -0000 1.2 --- class.cs 6 Oct 2004 13:46:44 -0000 1.3 *************** *** 4,7 **** --- 4,8 ---- // Authors: Miguel de Icaza (mi...@gn...) // Martin Baulig (ma...@gn...) + // Marek Safar (mar...@se...) // // Licensed under the terms of the GNU GPL *************** *** 35,89 **** using System.Reflection.Emit; using System.Runtime.CompilerServices; [...9884 lines suppressed...] - return false; - - if (!MemberSignatureCompare (m, filter_criteria)) - return false; - - // If only accessible to the defining assembly or - if (prot == MethodAttributes.FamANDAssem || - prot == MethodAttributes.Assembly){ - if (m.DeclaringType.Assembly == CodeGen.AssemblyBuilder) - return true; - else - return false; - } - - // Anything else (FamOrAssembly and Public) is fine - return true; - } } } --- 7107,7110 ---- Index: codegen.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/mcs/codegen.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** codegen.cs 16 Sep 2003 13:00:24 -0000 1.2 --- codegen.cs 6 Oct 2004 13:46:44 -0000 1.3 *************** *** 13,16 **** --- 13,20 ---- using System.Reflection; using System.Reflection.Emit; + using System.Runtime.InteropServices; + using System.Security.Cryptography; + + using Mono.Security.Cryptography; namespace Mono.CSharp { *************** [...1039 lines suppressed...] + ApplyAttributeBuilder (null, new CustomAttributeBuilder (TypeManager.unverifiable_code_ctor, new object [0])); + } + + public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder customBuilder) + { + if (a != null && a.Type == TypeManager.cls_compliant_attribute_type) { + Report.Warning (3012, a.Location, "You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking"); + return; + } + + Builder.SetCustomAttribute (customBuilder); + } + + public override string[] ValidAttributeTargets { + get { + return attribute_targets; + } + } + } } Index: compiler.sln =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/mcs/compiler.sln,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** compiler.sln 18 Feb 2003 07:36:40 -0000 1.1 --- compiler.sln 6 Oct 2004 13:46:44 -0000 1.2 *************** *** 1,21 **** ! Microsoft Visual Studio Solution File, Format Version 7.00 ! Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "compiler", "compiler.csproj", "{896D1461-B76B-41C0-ABE6-ACA2BB4F7B5A}" ! EndProject ! Global ! GlobalSection(SolutionConfiguration) = preSolution ! ConfigName.0 = Debug ! ConfigName.1 = Release ! EndGlobalSection ! GlobalSection(ProjectDependencies) = postSolution ! EndGlobalSection ! GlobalSection(ProjectConfiguration) = postSolution ! {896D1461-B76B-41C0-ABE6-ACA2BB4F7B5A}.Debug.ActiveCfg = Debug|.NET ! {896D1461-B76B-41C0-ABE6-ACA2BB4F7B5A}.Debug.Build.0 = Debug|.NET ! {896D1461-B76B-41C0-ABE6-ACA2BB4F7B5A}.Release.ActiveCfg = Release|.NET ! {896D1461-B76B-41C0-ABE6-ACA2BB4F7B5A}.Release.Build.0 = Release|.NET ! EndGlobalSection ! GlobalSection(ExtensibilityGlobals) = postSolution ! EndGlobalSection ! GlobalSection(ExtensibilityAddIns) = postSolution ! EndGlobalSection ! EndGlobal --- 1,21 ---- ! Microsoft Visual Studio Solution File, Format Version 8.00 ! Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "compiler", "compiler.csproj", "{896D1461-B76B-41C0-ABE6-ACA2BB4F7B5A}" ! ProjectSection(ProjectDependencies) = postProject ! EndProjectSection ! EndProject ! Global ! GlobalSection(SolutionConfiguration) = preSolution ! Debug = Debug ! Release = Release ! EndGlobalSection ! GlobalSection(ProjectConfiguration) = postSolution ! {896D1461-B76B-41C0-ABE6-ACA2BB4F7B5A}.Debug.ActiveCfg = Debug|.NET ! {896D1461-B76B-41C0-ABE6-ACA2BB4F7B5A}.Debug.Build.0 = Debug|.NET ! {896D1461-B76B-41C0-ABE6-ACA2BB4F7B5A}.Release.ActiveCfg = Release|.NET ! {896D1461-B76B-41C0-ABE6-ACA2BB4F7B5A}.Release.Build.0 = Release|.NET ! EndGlobalSection ! GlobalSection(ExtensibilityGlobals) = postSolution ! EndGlobalSection ! GlobalSection(ExtensibilityAddIns) = postSolution ! EndGlobalSection ! EndGlobal Index: const.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/mcs/const.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** const.cs 16 Sep 2003 13:00:24 -0000 1.2 --- const.cs 6 Oct 2004 13:46:44 -0000 1.3 *************** *** 25,36 **** using System.Collections; ! public class Const : MemberBase { ! public Expression ConstantType; public Expression Expr; - public FieldBuilder FieldBuilder; EmitContext const_ec; object ConstantValue = null; - Type type; bool in_transit = false; --- 25,34 ---- using System.Collections; ! public class Const : FieldMember { public Expression Expr; EmitContext const_ec; + bool resolved = false; object ConstantValue = null; bool in_transit = false; *************** *** 43,53 **** Modifiers.PRIVATE; ! public Const (Expression constant_type, string name, Expression expr, int mod_flags, ! Attributes attrs, Location loc) ! : base (constant_type, mod_flags, AllowedModifiers, Modifiers.PRIVATE, name, attrs, loc) { - ConstantType = constant_type; - Name = name; Expr = expr; } --- 41,51 ---- Modifiers.PRIVATE; ! public Const (TypeContainer parent, Expression constant_type, string name, ! Expression expr, int mod_flags, Attributes attrs, Location loc) ! : base (parent, constant_type, mod_flags, AllowedModifiers, ! new MemberName (name), null, attrs, loc) { Expr = expr; + ModFlags |= Modifiers.STATIC; } *************** *** 74,88 **** /// Defines the constant in the @parent /// </summary> ! public override bool Define (TypeContainer parent) { ! type = parent.ResolveType (ConstantType, false, Location); ! ! if (type == null) return false; ! const_ec = new EmitContext (parent, Location, null, type, ModFlags); ! if (!TypeManager.IsBuiltinType (type) && ! (!type.IsSubclassOf (TypeManager.enum_type))) { Report.Error ( -3, Location, --- 72,87 ---- /// Defines the constant in the @parent /// </summary> ! public override bool Define () { ! if (!base.Define ()) return false; ! const_ec = new EmitContext (Parent, Location, null, MemberType, ModFlags); ! ! Type ttype = MemberType; ! while (ttype.IsArray) ! ttype = TypeManager.GetElementType (ttype); ! if (!TypeManager.IsBuiltinType (ttype) && (!ttype.IsSubclassOf (TypeManager.enum_type)) && !(Expr is NullLiteral)) { Report.Error ( -3, Location, *************** *** 91,109 **** } ! Type ptype = parent.TypeBuilder.BaseType; ! ! if (ptype != null) { ! MemberList list = TypeContainer.FindMembers ( ! ptype, MemberTypes.Field, BindingFlags.Public, ! System.Type.FilterName, Name); ! ! if (list.Count == 0) ! if ((ModFlags & Modifiers.NEW) != 0) ! WarningNotHiding (parent); ! ! } else if ((ModFlags & Modifiers.NEW) != 0) ! WarningNotHiding (parent); ! ! FieldBuilder = parent.TypeBuilder.DefineField (Name, type, FieldAttr); TypeManager.RegisterConstant (FieldBuilder, this); --- 90,94 ---- } ! FieldBuilder = Parent.TypeBuilder.DefineField (Name, MemberType, FieldAttr); TypeManager.RegisterConstant (FieldBuilder, this); *************** *** 112,123 **** } /// <summary> /// Looks up the value of a constant field. Defines it if it hasn't /// already been. Similar to LookupEnumValue in spirit. /// </summary> ! public object LookupConstantValue () { ! if (ConstantValue != null) ! return ConstantValue; if (in_transit) { --- 97,175 ---- } + // + // Changes the type of the constant expression `expr' to the Type `type' + // Returns null on failure. + // + public static Constant ChangeType (Location loc, Constant expr, Type type) + { + if (type == TypeManager.object_type) + return expr; + + bool fail; + + // from the null type to any reference-type. + if (expr is NullLiteral && !type.IsValueType && !TypeManager.IsEnumType (type)) + return NullLiteral.Null; + + if (!Convert.ImplicitStandardConversionExists (expr, type)){ + Convert.Error_CannotImplicitConversion (loc, expr.Type, type); + return null; + } + + object constant_value = TypeManager.ChangeType (expr.GetValue (), type, out fail); + if (fail){ + Convert.Error_CannotImplicitConversion (loc, expr.Type, type); + + // + // We should always catch the error before this is ever + // reached, by calling Convert.ImplicitStandardConversionExists + // + throw new Exception ( + String.Format ("LookupConstantValue: This should never be reached {0} {1}", expr.Type, type)); + } + + Constant retval; + if (type == TypeManager.int32_type) + retval = new IntConstant ((int) constant_value); + else if (type == TypeManager.uint32_type) + retval = new UIntConstant ((uint) constant_value); + else if (type == TypeManager.int64_type) + retval = new LongConstant ((long) constant_value); + else if (type == TypeManager.uint64_type) + retval = new ULongConstant ((ulong) constant_value); + else if (type == TypeManager.float_type) + retval = new FloatConstant ((float) constant_value); + else if (type == TypeManager.double_type) + retval = new DoubleConstant ((double) constant_value); + else if (type == TypeManager.string_type) + retval = new StringConstant ((string) constant_value); + else if (type == TypeManager.short_type) + retval = new ShortConstant ((short) constant_value); + else if (type == TypeManager.ushort_type) + retval = new UShortConstant ((ushort) constant_value); + else if (type == TypeManager.sbyte_type) + retval = new SByteConstant ((sbyte) constant_value); + else if (type == TypeManager.byte_type) + retval = new ByteConstant ((byte) constant_value); + else if (type == TypeManager.char_type) + retval = new CharConstant ((char) constant_value); + else if (type == TypeManager.bool_type) + retval = new BoolConstant ((bool) constant_value); + else + throw new Exception ("LookupConstantValue: Unhandled constant type: " + type); + + return retval; + } + /// <summary> /// Looks up the value of a constant field. Defines it if it hasn't /// already been. Similar to LookupEnumValue in spirit. /// </summary> ! public bool LookupConstantValue (out object value) { ! if (resolved) { ! value = ConstantValue; ! return true; ! } if (in_transit) { *************** *** 125,129 **** "The evaluation of the constant value for `" + Name + "' involves a circular definition."); ! return null; } --- 177,182 ---- "The evaluation of the constant value for `" + Name + "' involves a circular definition."); !... [truncated message content] |
From: <mas...@us...> - 2004-10-06 13:45:44
|
Update of /cvsroot/csdoc/csdoc/src/build/deps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25576/deps Added Files: .cvsignore Log Message: 2004-10-06 Gaurav Vaish <mastergaurav@> * Getting the latest from mcs --- NEW FILE: .cvsignore --- *.makefrag *.response *.stamp *.was_signed |
From: <mas...@us...> - 2004-10-06 13:45:36
|
Update of /cvsroot/csdoc/csdoc/src/build In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25576 Added Files: config-default.make rules.make Log Message: 2004-10-06 Gaurav Vaish <mastergaurav@> * Getting the latest from mcs --- NEW FILE: config-default.make --- # -*- makefile -*- # # This makefile fragment has (default) configuration # settings for building MCS. # DO NOT EDIT THIS FILE! Create config.make and override settings # there. RUNTIME_FLAGS = TEST_HARNESS = $(topdir)/class/lib/$(PROFILE)/nunit-console.exe MCS_FLAGS = $(PLATFORM_DEBUG_FLAGS) MBAS_FLAGS = $(PLATFORM_DEBUG_FLAGS) LIBRARY_FLAGS = /noconfig CFLAGS = -g -O2 INSTALL = /usr/bin/install prefix = /usr/local RUNTIME = mono $(RUNTIME_FLAGS) TEST_RUNTIME = MONO_PATH="$(topdir)/class/lib/$(PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) --debug # In case you want to add MCS_FLAGS, this lets you not have to # keep track of the default value DEFAULT_MCS_FLAGS := $(MCS_FLAGS) DEFAULT_MBAS_FLAGS := $(MBAS_FLAGS) # You shouldn't need to set these but might on a # weird platform. # CC = cc # SHELL = /bin/sh # MAKE = gmake --- NEW FILE: rules.make --- # -*- makefile -*- # # This is the makefile fragment with default rules # for building things in MCS # # To customize the build, you should edit config.make. # If you need to edit this file, that's a bug; email # pe...@ne... about it. # Some more variables. The leading period in the sed expression prevents # thisdir = . from being changed into '..' for the toplevel directory. dots := $(shell echo $(thisdir) |sed -e 's,[^./][^/]*,..,g') topdir := $(dots) VERSION = 0.93 USE_MCS_FLAGS = $(LOCAL_MCS_FLAGS) $(PLATFORM_MCS_FLAGS) $(PROFILE_MCS_FLAGS) $(MCS_FLAGS) USE_MBAS_FLAGS = $(LOCAL_MBAS_FLAGS) $(PLATFORM_MBAS_FLAGS) $(PROFILE_MBAS_FLAGS) $(MBAS_FLAGS) USE_CFLAGS = $(LOCAL_CFLAGS) $(CFLAGS) CSCOMPILE = $(MCS) $(USE_MCS_FLAGS) BASCOMPILE = $(MBAS) $(USE_MBAS_FLAGS) CCOMPILE = $(CC) $(USE_CFLAGS) BOOT_COMPILE = $(BOOTSTRAP_MCS) $(USE_MCS_FLAGS) INSTALL_DATA = $(INSTALL) -m 644 INSTALL_BIN = $(INSTALL) -m 755 INSTALL_LIB = $(INSTALL_BIN) MKINSTALLDIRS = $(SHELL) $(topdir)/mkinstalldirs INTERNAL_MCS = $(RUNTIME) $(topdir)/mcs/mcs.exe INTERNAL_MBAS = $(RUNTIME) $(topdir)/mbas/mbas.exe INTERNAL_GMCS = $(RUNTIME) $(topdir)/gmcs/gmcs.exe INTERNAL_ILASM = $(RUNTIME) $(topdir)/ilasm/ilasm.exe INTERNAL_RESGEN = $(RUNTIME) $(topdir)/monoresgen/monoresgen.exe corlib = mscorlib.dll depsdir = $(topdir)/build/deps distdir = $(dots)/$(package)/$(thisdir) # Make sure these propagate if set manually export PLATFORM export PROFILE export MCS export MCS_FLAGS export CC export CFLAGS export INSTALL export MKINSTALLDIRS export TEST_HARNESS export BOOTSTRAP_MCS export DESTDIR export RESGEN # Get this so the platform.make platform-check rule doesn't become the # default target .DEFAULT: all default: all # Get initial configuration. pre-config is so that the builder can # override PLATFORM or PROFILE include $(topdir)/build/config-default.make -include $(topdir)/build/pre-config.make # Default PLATFORM and PROFILE if they're not already defined. ifndef PLATFORM ifeq ($(OS),Windows_NT) PLATFORM = win32 else PLATFORM = linux endif endif # Platform config include $(topdir)/build/platforms/$(PLATFORM).make ifdef PLATFORM_CORLIB corlib = $(PLATFORM_CORLIB) endif # Useful ifeq ($(PLATFORM_RUNTIME),$(RUNTIME)) PLATFORM_MONO_NATIVE = yes endif # Rest of the configuration ifndef PROFILE PROFILE = default endif include $(topdir)/build/profiles/$(PROFILE).make -include $(topdir)/build/config.make ifdef OVERRIDE_TARGET_ALL all: all.override else all: all.real endif all.real: all-recursive $(MAKE) all-local STD_TARGETS = test run-test run-test-ondotnet clean install uninstall $(STD_TARGETS): %: %-recursive $(MAKE) $@-local %-recursive: @set . $$MAKEFLAGS; \ case $$2 in --unix) shift ;; esac; \ case $$2 in *=*) dk="exit 1" ;; *k*) dk=: ;; *) dk="exit 1" ;; esac; \ list='$(SUBDIRS)'; for d in $$list ; do \ (cd $$d && $(MAKE) $*) || $$dk ; \ done # note: dist-local dep, extra subdirs, we invoke dist-recursive in the subdir too dist-recursive: dist-local @list='$(SUBDIRS) $(DIST_ONLY_SUBDIRS)'; for d in $$list ; do \ (cd $$d && $(MAKE) $@) || exit 1 ; \ done # Can only do this from the top dir # ## dist: dist-recursive dist-local # We invert the test here to not end in an error # if ChangeLog doesn't exist. # # Note that we error out if we try to dist a nonexistant # file. Seems reasonable to me. # # Pick up Makefile, makefile, or GNUmakefile dist-default: -mkdir -p $(distdir) test '!' -f ChangeLog || cp ChangeLog $(distdir) if test -f Makefile; then m=M; fi; \ if test -f makefile; then m=m; fi; \ if test -f GNUmakefile; then m=GNUm; fi; \ for f in $${m}akefile $(DISTFILES) ; do \ dest=`dirname $(distdir)/$$f` ; \ $(MKINSTALLDIRS) $$dest && cp $$f $$dest || exit 1 ; \ done # Useful withmcs: $(MAKE) MCS='$(INTERNAL_MCS)' BOOTSTRAP_MCS='$(INTERNAL_MCS)' all |
From: <mas...@us...> - 2004-10-06 13:45:26
|
Update of /cvsroot/csdoc/csdoc/src/build/platforms In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25576/platforms Added Files: linux.make win32.make Log Message: 2004-10-06 Gaurav Vaish <mastergaurav@> * Getting the latest from mcs --- NEW FILE: linux.make --- # -*- makefile -*- # # Platform-specific makefile rules. This one's for linux. # PLATFORM_DEBUG_FLAGS = -g PLATFORM_MCS_FLAGS = PLATFORM_RUNTIME = $(RUNTIME) PLATFORM_CORLIB = mscorlib.dll BOOTSTRAP_MCS = mcs RESGEN = MONO_PATH="$(topdir)/class/lib/$(PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(INTERNAL_RESGEN) PLATFORM_PATH_SEPARATOR = : # Define this if this ever will work on Linux # PLATFORM_MAKE_CORLIB_CMP = yes # This is for changing / to \ on windows PLATFORM_CHANGE_SEPARATOR_CMD = cat hidden_prefix = . hidden_suffix = platform-check: @set fnord $(BOOTSTRAP_MCS) ; if type $$2 >/dev/null 2>&1 ; then :; else \ echo "*** You need a C# compiler installed to build MCS. (make sure mcs works from the command line)" ; \ echo "*** Read INSTALL.txt for information on how to bootstrap" ; \ echo "*** a Mono installation." ; \ exit 1 ; \ fi # I tried this but apparently Make's version strings aren't that # ... consistent between releases. Whatever. # # @if ! $(MAKE) --version |grep '^GNU Make version 3' 1>/dev/null 2>&1 ; then \ # echo "*** You need to build MCS with GNU make. Try \`gmake'" ; \ # exit 1 ; \ # fi --- NEW FILE: win32.make --- # -*- makefile -*- # # Win32 platform-specific makefile rules. # PLATFORM_DEBUG_FLAGS = /debug+ /debug:full PLATFORM_MCS_FLAGS = /nologo /optimize PLATFORM_RUNTIME = PLATFORM_CORLIB = mscorlib.dll BOOTSTRAP_MCS = csc.exe MCS = $(BOOTSTRAP_MCS) RESGEN = resgen.exe PLATFORM_MAKE_CORLIB_CMP = yes PLATFORM_CHANGE_SEPARATOR_CMD=tr '/' '\\\\' PLATFORM_PATH_SEPARATOR = ; hidden_prefix = hidden_suffix = .tmp platform-check: |
Update of /cvsroot/csdoc/csdoc/src/build/profiles In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25576/profiles Added Files: atomic.make bootstrap.make default.make net_1_0.make net_2_0.make net_2_0_bootstrap.make Log Message: 2004-10-06 Gaurav Vaish <mastergaurav@> * Getting the latest from mcs --- NEW FILE: atomic.make --- # -*- Makefile -*- # # The 'atomic' profile. # In this profile we compile everything relative to the already-installed # runtime, so we use the bootstrap (external) compiler for everything and # don't set MONO_PATH. # # (So the libraries are compiled and installed atomically, not incrementally.) MCS = $(BOOTSTRAP_MCS) # Causes some build errors #PROFILE_MCS_FLAGS = /d:NET_1_1 /lib:$(prefix)/lib # Get our installed libraries (an issue on windows) PROFILE_MCS_FLAGS = /lib:$(prefix)/lib # Check that installed libraries even exist. profile-check: @if test '!' -f $(prefix)/lib/I18N.dll ; then \ echo ; \ echo "$(prefix)/lib/I18N.dll does not exist." ; \ echo ; \ echo "This probably means that you are building from a miniature" ; \ echo "distribution of MCS or don't yet have an installed MCS at all." ; \ echo "The current build profile needs a complete installation of" ; \ echo "MCS to build against; you need to build using the default" ; \ echo "profile. Use this command:" ; \ echo ; \ echo " $(MAKE) PROFILE=default" ; \ echo ; \ exit 1 ; \ fi # Exciting, no? --- NEW FILE: bootstrap.make --- # -*- makefile -*- # # The default 'bootstrap' profile -- builds so that we link against # the libraries as we build them. # # We use the platform's native C# runtime and compiler if possible. # Note that we have sort of confusing terminology here; BOOTSTRAP_MCS # is what allows us to bootstrap ourselves, but when we are bootstrapping, # we use INTERNAL_MCS. # When bootstrapping, compile against our new assemblies. # (MONO_PATH doesn't just affect what assemblies are loaded to # run the compiler; /r: flags are by default loaded from whatever's # in the MONO_PATH too). MCS = MONO_PATH="$(topdir)/class/lib/$(PROFILE):$$MONO_PATH" $(RUNTIME) --debug $(topdir)/mcs/mcs.exe BOOTSTRAP_MCS = $(MCS) # nuttzing! profile-check: # Causes some build errors PROFILE_MCS_FLAGS = -d:NET_1_1 -d:ONLY_1_1 --- NEW FILE: default.make --- # -*- makefile -*- # # The default 'bootstrap' profile -- builds so that we link against # the libraries as we build them. # # We use the platform's native C# runtime and compiler if possible. # Note that we have sort of confusing terminology here; BOOTSTRAP_MCS # is what allows us to bootstrap ourselves, but when we are bootstrapping, # we use INTERNAL_MCS. # When bootstrapping, compile against our new assemblies. # (MONO_PATH doesn't just affect what assemblies are loaded to # run the compiler; /r: flags are by default loaded from whatever's # in the MONO_PATH too). ifdef PLATFORM_MONO_NATIVE MCS = MONO_PATH="$(topdir)/class/lib/$(PROFILE):$$MONO_PATH" $(INTERNAL_MCS) MBAS = MONO_PATH="$(topdir)/class/lib/$(PROFILE):$$MONO_PATH" $(INTERNAL_MBAS) else MCS = $(PLATFORM_RUNTIME) $(BOOTSTRAP_MCS) /lib:$(topdir)/class/lib/$(PROFILE) MBAS = $(PLATFORM_RUNTIME) $(BOOTSTRAP_MBAS) /lib:$(topdir)/class/lib/$(PROFILE) endif # nuttzing! profile-check: PROFILE_MCS_FLAGS = -d:NET_1_1 -d:ONLY_1_1 PROFILE_MBAS_FLAGS = -d:NET_1_1 -d:ONLY_1_1 FRAMEWORK_VERSION = 1.0 --- NEW FILE: net_1_0.make --- # -*- Makefile -*- # # Only build .NET 1.0 classes. # # If we want to combine this with, say, the atomic profile, # we should create 'atomic-net_1_0.make' which includes both. # # Ideally you could say 'make PROFILE="bootstrap net_1_0"' but # that would be pretty hard to code. include $(topdir)/build/profiles/default.make PROFILE_MCS_FLAGS = /d:NET_1_0 /d:ONLY_1_0 FRAMEWORK_VERSION = 1.0 # done --- NEW FILE: net_2_0.make --- # -*- makefile -*- # # The default 'bootstrap' profile -- builds so that we link against # the libraries as we build them. # # We use the platform's native C# runtime and compiler if possible. # Note that we have sort of confusing terminology here; BOOTSTRAP_MCS # is what allows us to bootstrap ourselves, but when we are bootstrapping, # we use INTERNAL_MCS. # When bootstrapping, compile against our new assemblies. # (MONO_PATH doesn't just affect what assemblies are loaded to # run the compiler; /r: flags are by default loaded from whatever's # in the MONO_PATH too). MCS = MONO_PATH="$(topdir)/class/lib/$(PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(INTERNAL_GMCS) # nuttzing! profile-check: PROFILE_MCS_FLAGS = -d:NET_1_1 -d:NET_2_0 -2 FRAMEWORK_VERSION = 2.0 --- NEW FILE: net_2_0_bootstrap.make --- # -*- makefile -*- # # Note that we're using the .NET 1.1 MCS but MONO_PATH points to the net_2_0_bootstrap directory. # We do it this way to get assembly version references right. # MCS = MONO_PATH="$(topdir)/class/lib/$(PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(INTERNAL_MCS) # Make sure that we're not invoked at the top-level. profile-check: echo "The 'net_2_0_bootstrap' profile is for internal use only" exit 1 PROFILE_MCS_FLAGS = -d:NET_1_1 -d:BOOTSTRAP_NET_2_0 -langversion:default FRAMEWORK_VERSION = 2.0 NO_SIGN_ASSEMBLY = yes |
From: <mas...@us...> - 2004-10-06 13:44:49
|
Update of /cvsroot/csdoc/csdoc/src/build/deps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25134/deps Log Message: Directory /cvsroot/csdoc/csdoc/src/build/deps added to the repository |
Update of /cvsroot/csdoc/csdoc/src/mcs In directory sc8-pr-cvs1:/tmp/cvs-serv20799 Modified Files: .cvsignore AssemblyInfo.cs ChangeLog TODO assign.cs attribute.cs cfold.cs class.cs codegen.cs const.cs constant.cs cs-parser.jay cs-tokenizer.cs decl.cs delegate.cs driver.cs ecore.cs enum.cs expression.cs interface.cs literal.cs location.cs makefile modifiers.cs namespace.cs parameter.cs pending.cs report.cs rootcontext.cs statement.cs support.cs symbolwriter.cs tree.cs typemanager.cs Added Files: anonymous.cs convert.cs flowanalysis.cs generic.cs iterators.cs Log Message: 2003-09-16 Gaurav Vaish <mastergaurav~AT~users.sf.net> * => Latest code from Mono/mcs --- NEW FILE --- // // anonymous.cs: Support for anonymous methods // // Author: // Miguel de Icaza (mi...@xi...) // // (C) 2003 Ximian, Inc. // using System; using System.Collections; using System.Reflection; using System.Reflection.Emit; namespace Mono.CSharp { public class AnonymousMethod : Expression { // An array list of AnonymousMethodParameter or null Parameters parameters; Block block; public AnonymousMethod (Parameters parameters, Block block, Location l) { this.parameters = parameters; this.block = block; loc = l; } public override Expression DoResolve (EmitContext ec) { // // Set class type, set type // eclass = ExprClass.Value; // // This hack means `The type is not accessible // anywhere', we depend on special conversion // rules. // type = typeof (AnonymousMethod); return this; } public override void Emit (EmitContext ec) { // nothing, as we only exist to not do anything. } } } --- NEW FILE --- // // conversion.cs: various routines for implementing conversions. // // Authors: // Miguel de Icaza (mi...@xi...) // Ravi Pratap (ra...@xi...) // // (C) 2001, 2002, 2003 Ximian, Inc. // namespace Mono.CSharp { using System; using System.Collections; using System.Diagnostics; using System.Reflection; using System.Reflection.Emit; // // A container class for all the conversion operations // public class Convert { static public void Error_CannotConvertType (Location loc, Type source, Type target) { Report.Error (30, loc, "Cannot convert type '" + TypeManager.CSharpName (source) + "' to '" + TypeManager.CSharpName (target) + "'"); } static EmptyExpression MyEmptyExpr; static public Expression ImplicitReferenceConversion (Expression expr, Type target_type) { Type expr_type = expr.Type; if (expr_type == null && expr.eclass == ExprClass.MethodGroup){ // if we are a method group, emit a warning expr.Emit (null); } // // notice that it is possible to write "ValueType v = 1", the ValueType here // is an abstract class, and not really a value type, so we apply the same rules. // if (target_type == TypeManager.object_type) { // // A pointer type cannot be converted to object // if (expr_type.IsPointer) return null; if (expr_type.IsValueType) return new BoxedCast (expr); if (expr_type.IsClass || expr_type.IsInterface || expr_type == TypeManager.enum_type) return new EmptyCast (expr, target_type); } else if (target_type == TypeManager.value_type) { if (expr_type.IsValueType) return new BoxedCast (expr); if (expr is NullLiteral) return new BoxedCast (expr); } else if (expr_type.IsSubclassOf (target_type)) { // // Special case: enumeration to System.Enum. // System.Enum is not a value type, it is a class, so we need // a boxing conversion // if (expr_type.IsEnum) return new BoxedCast (expr); return new EmptyCast (expr, target_type); } else { // This code is kind of mirrored inside ImplicitStandardConversionExists // with the small distinction that we only probe there // // Always ensure that the code here and there is in sync // from the null type to any reference-type. if (expr is NullLiteral){ if (target_type.IsPointer) return NullPointer.Null; if (!target_type.IsValueType) return new NullCast (expr, target_type); } // from any class-type S to any interface-type T. if (target_type.IsInterface) { if (TypeManager.ImplementsInterface (expr_type, target_type)){ if (expr_type.IsClass) return new EmptyCast (expr, target_type); else if (expr_type.IsValueType) return new BoxedCast (expr, target_type); } } // from any interface type S to interface-type T. if (expr_type.IsInterface && target_type.IsInterface) { if (TypeManager.ImplementsInterface (expr_type, target_type)) return new EmptyCast (expr, target_type); else return null; } // from an array-type S to an array-type of type T if (expr_type.IsArray && target_type.IsArray) { if (expr_type.GetArrayRank () == target_type.GetArrayRank ()) { Type expr_element_type = TypeManager.GetElementType (expr_type); if (MyEmptyExpr == null) MyEmptyExpr = new EmptyExpression (); MyEmptyExpr.SetType (expr_element_type); Type target_element_type = TypeManager.GetElementType (target_type); if (!expr_element_type.IsValueType && !target_element_type.IsValueType) if (ImplicitStandardConversionExists (MyEmptyExpr, target_element_type)) return new EmptyCast (expr, target_type); } } // from an array-type to System.Array if (expr_type.IsArray && target_type == TypeManager.array_type) return new EmptyCast (expr, target_type); // from any delegate type to System.Delegate if ((expr_type == TypeManager.delegate_type || expr_type.IsSubclassOf (TypeManager.delegate_type)) && target_type == TypeManager.delegate_type) return new EmptyCast (expr, target_type); // from any array-type or delegate type into System.ICloneable. if (expr_type.IsArray || expr_type == TypeManager.delegate_type || expr_type.IsSubclassOf (TypeManager.delegate_type)) if (target_type == TypeManager.icloneable_type) return new EmptyCast (expr, target_type); return null; } return null; } // // Tests whether an implicit reference conversion exists between expr_type // and target_type // public static bool ImplicitReferenceConversionExists (Expression expr, Type target_type) { Type expr_type = expr.Type; // // This is the boxed case. // if (target_type == TypeManager.object_type) { if (expr_type.IsClass || expr_type.IsValueType || expr_type.IsInterface || expr_type == TypeManager.enum_type) return true; } else if (expr_type.IsSubclassOf (target_type)) { return true; } else { // Please remember that all code below actually comes // from ImplicitReferenceConversion so make sure code remains in sync // from any class-type S to any interface-type T. if (target_type.IsInterface) { if (TypeManager.ImplementsInterface (expr_type, target_type)) return true; } // from any interface type S to interface-type T. if (expr_type.IsInterface && target_type.IsInterface) if (TypeManager.ImplementsInterface (expr_type, target_type)) return true; // from an array-type S to an array-type of type T if (expr_type.IsArray && target_type.IsArray) { if (expr_type.GetArrayRank () == target_type.GetArrayRank ()) { Type expr_element_type = expr_type.GetElementType (); if (MyEmptyExpr == null) MyEmptyExpr = new EmptyExpression (); MyEmptyExpr.SetType (expr_element_type); Type target_element_type = TypeManager.GetElementType (target_type); if (!expr_element_type.IsValueType && !target_element_type.IsValueType) if (ImplicitStandardConversionExists (MyEmptyExpr, target_element_type)) return true; } } // from an array-type to System.Array if (expr_type.IsArray && (target_type == TypeManager.array_type)) return true; // from any delegate type to System.Delegate if ((expr_type == TypeManager.delegate_type || expr_type.IsSubclassOf (TypeManager.delegate_type)) && target_type == TypeManager.delegate_type) if (target_type.IsAssignableFrom (expr_type)) return true; // from any array-type or delegate type into System.ICloneable. if (expr_type.IsArray || expr_type == TypeManager.delegate_type || expr_type.IsSubclassOf (TypeManager.delegate_type)) if (target_type == TypeManager.icloneable_type) return true; // from the null type to any reference-type. if (expr is NullLiteral && !target_type.IsValueType && !TypeManager.IsEnumType (target_type)) return true; } return false; } /// <summary> /// Implicit Numeric Conversions. /// /// expr is the expression to convert, returns a new expression of type /// target_type or null if an implicit conversion is not possible. /// </summary> static public Expression ImplicitNumericConversion (EmitContext ec, Expression expr, Type target_type, Location loc) { Type expr_type = expr.Type; // // Attempt to do the implicit constant expression conversions if (expr is Constant){ if (expr is IntConstant){ Expression e; e = TryImplicitIntConversion (target_type, (IntConstant) expr); if (e != null) return e; } else if (expr is LongConstant && target_type == TypeManager.uint64_type){ // // Try the implicit constant expression conversion // from long to ulong, instead of a nice routine, // we just inline it // long v = ((LongConstant) expr).Value; if (v > 0) return new ULongConstant ((ulong) v); } } Type real_target_type = target_type; if (expr_type == TypeManager.sbyte_type){ // // From sbyte to short, int, long, float, double. // if (real_target_type == TypeManager.int32_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_I4); if (real_target_type == TypeManager.int64_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_I8); if (real_target_type == TypeManager.double_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_R8); if (real_target_type == TypeManager.float_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_R4); if (real_target_type == TypeManager.short_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_I2); } else if (expr_type == TypeManager.byte_type){ // // From byte to short, ushort, int, uint, long, ulong, float, double // if ((real_target_type == TypeManager.short_type) || (real_target_type == TypeManager.ushort_type) || (real_target_type == TypeManager.int32_type) || (real_target_type == TypeManager.uint32_type)) return new EmptyCast (expr, target_type); if (real_target_type == TypeManager.uint64_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_U8); if (real_target_type == TypeManager.int64_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_I8); if (real_target_type == TypeManager.float_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_R4); if (real_target_type == TypeManager.double_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_R8); } else if (expr_type == TypeManager.short_type){ // // From short to int, long, float, double // if (real_target_type == TypeManager.int32_type) return new EmptyCast (expr, target_type); if (real_target_type == TypeManager.int64_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_I8); if (real_target_type == TypeManager.double_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_R8); if (real_target_type == TypeManager.float_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_R4); } else if (expr_type == TypeManager.ushort_type){ // // From ushort to int, uint, long, ulong, float, double // if (real_target_type == TypeManager.uint32_type) return new EmptyCast (expr, target_type); if (real_target_type == TypeManager.uint64_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_U8); if (real_target_type == TypeManager.int32_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_I4); if (real_target_type == TypeManager.int64_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_I8); if (real_target_type == TypeManager.double_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_R8); if (real_target_type == TypeManager.float_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_R4); } else if (expr_type == TypeManager.int32_type){ // // From int to long, float, double // if (real_target_type == TypeManager.int64_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_I8); if (real_target_type == TypeManager.double_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_R8); if (real_target_type == TypeManager.float_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_R4); } else if (expr_type == TypeManager.uint32_type){ // // From uint to long, ulong, float, double // if (real_target_type == TypeManager.int64_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_U8); if (real_target_type == TypeManager.uint64_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_U8); if (real_target_type == TypeManager.double_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_R_Un, OpCodes.Conv_R8); if (real_target_type == TypeManager.float_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_R_Un, OpCodes.Conv_R4); } else if (expr_type == TypeManager.int64_type){ // // From long/ulong to float, double // if (real_target_type == TypeManager.double_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_R8); if (real_target_type == TypeManager.float_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_R4); } else if (expr_type == TypeManager.uint64_type){ // // From ulong to float, double // if (real_target_type == TypeManager.double_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_R_Un, OpCodes.Conv_R8); if (real_target_type == TypeManager.float_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_R_Un, OpCodes.Conv_R4); } else if (expr_type == TypeManager.char_type){ // // From char to ushort, int, uint, long, ulong, float, double // if ((real_target_type == TypeManager.ushort_type) || (real_target_type == TypeManager.int32_type) || (real_target_type == TypeManager.uint32_type)) return new EmptyCast (expr, target_type); if (real_target_type == TypeManager.uint64_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_U8); if (real_target_type == TypeManager.int64_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_I8); if (real_target_type == TypeManager.float_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_R4); if (real_target_type == TypeManager.double_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_R8); } else if (expr_type == TypeManager.float_type){ // // float to double // if (real_target_type == TypeManager.double_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_R8); } return null; } /// <summary> /// Same as ImplicitStandardConversionExists except that it also looks at /// implicit user defined conversions - needed for overload resolution /// </summary> public static bool ImplicitConversionExists (EmitContext ec, Expression expr, Type target_type) { if (ImplicitStandardConversionExists (expr, target_type)) return true; Expression dummy = ImplicitUserConversion (ec, expr, target_type, Location.Null); if (dummy != null) return true; return false; } public static bool ImplicitUserConversionExists (EmitContext ec, Type source, Type target) { Expression dummy = ImplicitUserConversion ( ec, new EmptyExpression (source), target, Location.Null); return dummy != null; } /// <summary> /// Determines if a standard implicit conversion exists from /// expr_type to target_type /// </summary> public static bool ImplicitStandardConversionExists (Expression expr, Type target_type) { Type expr_type = expr.Type; if (expr_type == TypeManager.void_type) return false; if (expr_type == target_type) return true; // First numeric conversions if (expr_type == TypeManager.sbyte_type){ // // From sbyte to short, int, long, float, double. // if ((target_type == TypeManager.int32_type) || (target_type == TypeManager.int64_type) || (target_type == TypeManager.double_type) || (target_type == TypeManager.float_type) || (target_type == TypeManager.short_type) || (target_type == TypeManager.decimal_type)) return true; } else if (expr_type == TypeManager.byte_type){ // // From byte to short, ushort, int, uint, long, ulong, float, double // if ((target_type == TypeManager.short_type) || (target_type == TypeManager.ushort_type) || (target_type == TypeManager.int32_type) || (target_type == TypeManager.uint32_type) || (target_type == TypeManager.uint64_type) || (target_type == TypeManager.int64_type) || (target_type == TypeManager.float_type) || (target_type == TypeManager.double_type) || (target_type == TypeManager.decimal_type)) return true; } else if (expr_type == TypeManager.short_type){ // // From short to int, long, float, double // if ((target_type == TypeManager.int32_type) || (target_type == TypeManager.int64_type) || (target_type == TypeManager.double_type) || (target_type == TypeManager.float_type) || (target_type == TypeManager.decimal_type)) return true; } else if (expr_type == TypeManager.ushort_type){ // // From ushort to int, uint, long, ulong, float, double // if ((target_type == TypeManager.uint32_type) || (target_type == TypeManager.uint64_type) || (target_type == TypeManager.int32_type) || (target_type == TypeManager.int64_type) || (target_type == TypeManager.double_type) || (target_type == TypeManager.float_type) || (target_type == TypeManager.decimal_type)) return true; } else if (expr_type == TypeManager.int32_type){ // // From int to long, float, double // if ((target_type == TypeManager.int64_type) || (target_type == TypeManager.double_type) || (target_type == TypeManager.float_type) || (target_type == TypeManager.decimal_type)) return true; } else if (expr_type == TypeManager.uint32_type){ // // From uint to long, ulong, float, double // if ((target_type == TypeManager.int64_type) || (target_type == TypeManager.uint64_type) || (target_type == TypeManager.double_type) || (target_type == TypeManager.float_type) || (target_type == TypeManager.decimal_type)) return true; } else if ((expr_type == TypeManager.uint64_type) || (expr_type == TypeManager.int64_type)) { // // From long/ulong to float, double // if ((target_type == TypeManager.double_type) || (target_type == TypeManager.float_type) || (target_type == TypeManager.decimal_type)) return true; } else if (expr_type == TypeManager.char_type){ // // From char to ushort, int, uint, long, ulong, float, double // if ((target_type == TypeManager.ushort_type) || (target_type == TypeManager.int32_type) || (target_type == TypeManager.uint32_type) || (target_type == TypeManager.uint64_type) || (target_type == TypeManager.int64_type) || (target_type == TypeManager.float_type) || (target_type == TypeManager.double_type) || (target_type == TypeManager.decimal_type)) return true; } else if (expr_type == TypeManager.float_type){ // // float to double // if (target_type == TypeManager.double_type) return true; } if (ImplicitReferenceConversionExists (expr, target_type)) return true; if (expr is IntConstant){ int value = ((IntConstant) expr).Value; if (target_type == TypeManager.sbyte_type){ if (value >= SByte.MinValue && value <= SByte.MaxValue) return true; } else if (target_type == TypeManager.byte_type){ if (Byte.MinValue >= 0 && value <= Byte.MaxValue) return true; } else if (target_type == TypeManager.short_type){ if (value >= Int16.MinValue && value <= Int16.MaxValue) return true; } else if (target_type == TypeManager.ushort_type){ if (value >= UInt16.MinValue && value <= UInt16.MaxValue) return true; } else if (target_type == TypeManager.uint32_type){ if (value >= 0) return true; } else if (target_type == TypeManager.uint64_type){ // // we can optimize this case: a positive int32 // always fits on a uint64. But we need an opcode // to do it. // if (value >= 0) return true; } if (value == 0 && expr is IntLiteral && TypeManager.IsEnumType (target_type)) return true; } if (expr is LongConstant && target_type == TypeManager.uint64_type){ // // Try the implicit constant expression conversion // from long to ulong, instead of a nice routine, // we just inline it // long v = ((LongConstant) expr).Value; if (v > 0) return true; } if ((target_type == TypeManager.enum_type || target_type.IsSubclassOf (TypeManager.enum_type)) && expr is IntLiteral){ IntLiteral i = (IntLiteral) expr; if (i.Value == 0) return true; } if (target_type == TypeManager.void_ptr_type && expr_type.IsPointer) return true; return false; } // // Used internally by FindMostEncompassedType, this is used // to avoid creating lots of objects in the tight loop inside // FindMostEncompassedType // static EmptyExpression priv_fmet_param; /// <summary> /// Finds "most encompassed type" according to the spec (13.4.2) /// amongst the methods in the MethodGroupExpr /// </summary> static Type FindMostEncompassedType (ArrayList types) { Type best = null; if (priv_fmet_param == null) priv_fmet_param = new EmptyExpression (); foreach (Type t in types){ priv_fmet_param.SetType (t); if (best == null) { best = t; continue; } if (ImplicitStandardConversionExists (priv_fmet_param, best)) best = t; } return best; } // // Used internally by FindMostEncompassingType, this is used // to avoid creating lots of objects in the tight loop inside // FindMostEncompassingType // static EmptyExpression priv_fmee_ret; /// <summary> /// Finds "most encompassing type" according to the spec (13.4.2) /// amongst the types in the given set /// </summary> static Type FindMostEncompassingType (ArrayList types) { Type best = null; if (priv_fmee_ret == null) priv_fmee_ret = new EmptyExpression (); foreach (Type t in types){ priv_fmee_ret.SetType (best); if (best == null) { best = t; continue; } if (ImplicitStandardConversionExists (priv_fmee_ret, t)) best = t; } return best; } // // Used to avoid creating too many objects // static EmptyExpression priv_fms_expr; /// <summary> /// Finds the most specific source Sx according to the rules of the spec (13.4.4) /// by making use of FindMostEncomp* methods. Applies the correct rules separately /// for explicit and implicit conversion operators. /// </summary> static public Type FindMostSpecificSource (MethodGroupExpr me, Expression source, bool apply_explicit_conv_rules, Location loc) { ArrayList src_types_set = new ArrayList (); if (priv_fms_expr == null) priv_fms_expr = new EmptyExpression (); // // If any operator converts from S then Sx = S // Type source_type = source.Type; foreach (MethodBase mb in me.Methods){ ParameterData pd = Invocation.GetParameterData (mb); Type param_type = pd.ParameterType (0); if (param_type == source_type) return param_type; if (apply_explicit_conv_rules) { // // From the spec : // Find the set of applicable user-defined conversion operators, U. This set // consists of the // user-defined implicit or explicit conversion operators declared by // the classes or structs in D that convert from a type encompassing // or encompassed by S to a type encompassing or encompassed by T // priv_fms_expr.SetType (param_type); if (ImplicitStandardConversionExists (priv_fms_expr, source_type)) src_types_set.Add (param_type); else { if (ImplicitStandardConversionExists (source, param_type)) src_types_set.Add (param_type); } } else { // // Only if S is encompassed by param_type // if (ImplicitStandardConversionExists (source, param_type)) src_types_set.Add (param_type); } } // // Explicit Conv rules // if (apply_explicit_conv_rules) { ArrayList candidate_set = new ArrayList (); foreach (Type param_type in src_types_set){ if (ImplicitStandardConversionExists (source, param_type)) candidate_set.Add (param_type); } if (candidate_set.Count != 0) return FindMostEncompassedType (candidate_set); } // // Final case // if (apply_explicit_conv_rules) return FindMostEncompassingType (src_types_set); else return FindMostEncompassedType (src_types_set); } // // Useful in avoiding proliferation of objects // static EmptyExpression priv_fmt_expr; /// <summary> /// Finds the most specific target Tx according to section 13.4.4 /// </summary> static public Type FindMostSpecificTarget (MethodGroupExpr me, Type target, bool apply_explicit_conv_rules, Location loc) { ArrayList tgt_types_set = new ArrayList (); if (priv_fmt_expr == null) priv_fmt_expr = new EmptyExpression (); // // If any operator converts to T then Tx = T // foreach (MethodInfo mi in me.Methods){ Type ret_type = mi.ReturnType; if (ret_type == target) return ret_type; if (apply_explicit_conv_rules) { // // From the spec : // Find the set of applicable user-defined conversion operators, U. // // This set consists of the // user-defined implicit or explicit conversion operators declared by // the classes or structs in D that convert from a type encompassing // or encompassed by S to a type encompassing or encompassed by T // priv_fms_expr.SetType (ret_type); if (ImplicitStandardConversionExists (priv_fms_expr, target)) tgt_types_set.Add (ret_type); else { priv_fms_expr.SetType (target); if (ImplicitStandardConversionExists (priv_fms_expr, ret_type)) tgt_types_set.Add (ret_type); } } else { // // Only if T is encompassed by param_type // priv_fms_expr.SetType (ret_type); if (ImplicitStandardConversionExists (priv_fms_expr, target)) tgt_types_set.Add (ret_type); } } // // Explicit conv rules // if (apply_explicit_conv_rules) { ArrayList candidate_set = new ArrayList (); foreach (Type ret_type in tgt_types_set){ priv_fmt_expr.SetType (ret_type); if (ImplicitStandardConversionExists (priv_fmt_expr, target)) candidate_set.Add (ret_type); } if (candidate_set.Count != 0) return FindMostEncompassingType (candidate_set); } // // Okay, final case ! // if (apply_explicit_conv_rules) return FindMostEncompassedType (tgt_types_set); else return FindMostEncompassingType (tgt_types_set); } /// <summary> /// User-defined Implicit conversions /// </summary> static public Expression ImplicitUserConversion (EmitContext ec, Expression source, Type target, Location loc) { return UserDefinedConversion (ec, source, target, loc, false); } /// <summary> /// User-defined Explicit conversions /// </summary> static public Expression ExplicitUserConversion (EmitContext ec, Expression source, Type target, Location loc) { return UserDefinedConversion (ec, source, target, loc, true); } /// <summary> /// Computes the MethodGroup for the user-defined conversion /// operators from source_type to target_type. `look_for_explicit' /// controls whether we should also include the list of explicit /// operators /// </summary> static MethodGroupExpr GetConversionOperators (EmitContext ec, Type source_type, Type target_type, Location loc, bool look_for_explicit) { Expression mg1 = null, mg2 = null; Expression mg5 = null, mg6 = null, mg7 = null, mg8 = null; string op_name; op_name = "op_Implicit"; MethodGroupExpr union3; mg1 = Expression.MethodLookup (ec, source_type, op_name, loc); if (source_type.BaseType != null) mg2 = Expression.MethodLookup (ec, source_type.BaseType, op_name, loc); if (mg1 == null) union3 = (MethodGroupExpr) mg2; else if (mg2 == null) union3 = (MethodGroupExpr) mg1; else union3 = Invocation.MakeUnionSet (mg1, mg2, loc); mg1 = Expression.MethodLookup (ec, target_type, op_name, loc); if (mg1 != null){ if (union3 != null) union3 = Invocation.MakeUnionSet (union3, mg1, loc); else union3 = (MethodGroupExpr) mg1; } if (target_type.BaseType != null) mg1 = Expression.MethodLookup (ec, target_type.BaseType, op_name, loc); if (mg1 != null){ if (union3 != null) union3 = Invocation.MakeUnionSet (union3, mg1, loc); else union3 = (MethodGroupExpr) mg1; } MethodGroupExpr union4 = null; if (look_for_explicit) { op_name = "op_Explicit"; mg5 = Expression.MemberLookup (ec, source_type, op_name, loc); if (source_type.BaseType != null) mg6 = Expression.MethodLookup (ec, source_type.BaseType, op_name, loc); mg7 = Expression.MemberLookup (ec, target_type, op_name, loc); if (target_type.BaseType != null) mg8 = Expression.MethodLookup (ec, target_type.BaseType, op_name, loc); MethodGroupExpr union5 = Invocation.MakeUnionSet (mg5, mg6, loc); MethodGroupExpr union6 = Invocation.MakeUnionSet (mg7, mg8, loc); union4 = Invocation.MakeUnionSet (union5, union6, loc); } return Invocation.MakeUnionSet (union3, union4, loc); } /// <summary> /// User-defined conversions /// </summary> static public Expression UserDefinedConversion (EmitContext ec, Expression source, Type target, Location loc, bool look_for_explicit) { MethodGroupExpr union; Type source_type = source.Type; MethodBase method = null; union = GetConversionOperators (ec, source_type, target, loc, look_for_explicit); if (union == null) return null; Type most_specific_source, most_specific_target; most_specific_source = FindMostSpecificSource (union, source, look_for_explicit, loc); if (most_specific_source == null) return null; most_specific_target = FindMostSpecificTarget (union, target, look_for_explicit, loc); if (most_specific_target == null) return null; int count = 0; foreach (MethodBase mb in union.Methods){ ParameterData pd = Invocation.GetParameterData (mb); MethodInfo mi = (MethodInfo) mb; if (pd.ParameterType (0) == most_specific_source && mi.ReturnType == most_specific_target) { method = mb; count++; } } if (method == null || count > 1) return null; // // This will do the conversion to the best match that we // found. Now we need to perform an implict standard conversion // if the best match was not the type that we were requested // by target. // if (look_for_explicit) source = ExplicitConversionStandard (ec, source, most_specific_source, loc); else source = ImplicitConversionStandard (ec, source, most_specific_source, loc); if (source == null) return null; Expression e; e = new UserCast ((MethodInfo) method, source, loc); if (e.Type != target){ if (!look_for_explicit) e = ImplicitConversionStandard (ec, e, target, loc); else e = ExplicitConversionStandard (ec, e, target, loc); } return e; } /// <summary> /// Converts implicitly the resolved expression `expr' into the /// `target_type'. It returns a new expression that can be used /// in a context that expects a `target_type'. /// </summary> static public Expression ImplicitConversion (EmitContext ec, Expression expr, Type target_type, Location loc) { Type expr_type = expr.Type; Expression e; if (target_type == null) throw new Exception ("Target type is null"); e = ImplicitConversionStandard (ec, expr, target_type, loc); if (e != null) return e; e = ImplicitUserConversion (ec, expr, target_type, loc); if (e != null) return e; return null; } /// <summary> /// Attempts to apply the `Standard Implicit /// Conversion' rules to the expression `expr' into /// the `target_type'. It returns a new expression /// that can be used in a context that expects a /// `target_type'. /// /// This is different from `ImplicitConversion' in that the /// user defined implicit conversions are excluded. /// </summary> static public Expression ImplicitConversionStandard (EmitContext ec, Expression expr, Type target_type, Location loc) { Type expr_type = expr.Type; Expression e; if (expr_type == target_type && !(expr is NullLiteral)) return expr; e = ImplicitNumericConversion (ec, expr, target_type, loc); if (e != null) return e; e = ImplicitReferenceConversion (expr, target_type); if (e != null) return e; if ((target_type == TypeManager.enum_type || target_type.IsSubclassOf (TypeManager.enum_type)) && expr is IntLiteral){ IntLiteral i = (IntLiteral) expr; if (i.Value == 0) return new EnumConstant ((Constant) expr, target_type); } if (ec.InUnsafe) { if (expr_type.IsPointer){ if (target_type == TypeManager.void_ptr_type) return new EmptyCast (expr, target_type); // // yep, comparing pointer types cant be done with // t1 == t2, we have to compare their element types. // if (target_type.IsPointer){ if (TypeManager.GetElementType(target_type) == TypeManager.GetElementType(expr_type)) return expr; } } if (target_type.IsPointer) { if (expr is NullLiteral) return new EmptyCast (expr, target_type); if (expr_type == TypeManager.void_ptr_type) return new EmptyCast (expr, target_type); } } return null; } /// <summary> /// Attemps to perform an implict constant conversion of the IntConstant /// into a different data type using casts (See Implicit Constant /// Expression Conversions) /// </summary> static public Expression TryImplicitIntConversion (Type target_type, IntConstant ic) { int value = ic.Value; if (target_type == TypeManager.sbyte_type){ if (value >= SByte.MinValue && value <= SByte.MaxValue) return new SByteConstant ((sbyte) value); } else if (target_type == TypeManager.byte_type){ if (Byte.MinValue >= 0 && value <= Byte.MaxValue) return new ByteConstant ((byte) value); } else if (target_type == TypeManager.short_type){ if (value >= Int16.MinValue && value <= Int16.MaxValue) return new ShortConstant ((short) value); } else if (target_type == TypeManager.ushort_type){ if (value >= UInt16.MinValue && value <= UInt16.MaxValue) return new UShortConstant ((ushort) value); } else if (target_type == TypeManager.uint32_type){ if (value >= 0) return new UIntConstant ((uint) value); } else if (target_type == TypeManager.uint64_type){ // // we can optimize this case: a positive int32 // always fits on a uint64. But we need an opcode // to do it. // if (value >= 0) return new ULongConstant ((ulong) value); } else if (target_type == TypeManager.double_type) return new DoubleConstant ((double) value); else if (target_type == TypeManager.float_type) return new FloatConstant ((float) value); if (value == 0 && ic is IntLiteral && TypeManager.IsEnumType (target_type)){ Type underlying = TypeManager.EnumToUnderlying (target_type); Constant e = (Constant) ic; // // Possibly, we need to create a different 0 literal before passing // to EnumConstant //n if (underlying == TypeManager.int64_type) e = new LongLiteral (0); else if (underlying == TypeManager.uint64_type) e = new ULongLiteral (0); return new EnumConstant (e, target_type); } return null; } static public void Error_CannotImplicitConversion (Location loc, Type source, Type target) { string msg = "Cannot convert implicitly from `"+ TypeManager.CSharpName (source) + "' to `" + TypeManager.CSharpName (target) + "'"; Report.Error (29, loc, msg); } /// <summary> /// Attemptes to implicityly convert `target' into `type', using /// ImplicitConversion. If there is no implicit conversion, then /// an error is signaled /// </summary> static public Expression ImplicitConversionRequired (EmitContext ec, Expression source, Type target_type, Location loc) { Expression e; e = ImplicitConversion (ec, source, target_type, loc); if (e != null) return e; if (source is DoubleLiteral && target_type == TypeManager.float_type){ Report.Error (664, loc, "Double literal cannot be implicitly converted to " + "float type, use F suffix to create a float literal"); } Error_CannotImplicitConversion (loc, source.Type, target_type); return null; } /// <summary> /// Performs the explicit numeric conversions /// </summary> static Expression ExplicitNumericConversion (EmitContext ec, Expression expr, Type target_type, Location loc) { Type expr_type = expr.Type; // // If we have an enumeration, extract the underlying type, // use this during the comparison, but wrap around the original // target_type // Type real_target_type = target_type; if (TypeManager.IsEnumType (real_target_type)) real_target_type = TypeManager.EnumToUnderlying (real_target_type); if (ImplicitStandardConversionExists (expr, real_target_type)){ Expression ce = ImplicitConversionStandard (ec, expr, real_target_type, loc); if (real_target_type != target_type) return new EmptyCast (ce, target_type); return ce; } if (expr_type == TypeManager.sbyte_type){ // // From sbyte to byte, ushort, uint, ulong, char // if (real_target_type == TypeManager.byte_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I1_U1); if (real_target_type == TypeManager.ushort_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I1_U2); if (real_target_type == TypeManager.uint32_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I1_U4); if (real_target_type == TypeManager.uint64_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I1_U8); if (real_target_type == TypeManager.char_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I1_CH); } else if (expr_type == TypeManager.byte_type){ // // From byte to sbyte and char // if (real_target_type == TypeManager.sbyte_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.U1_I1); if (real_target_type == TypeManager.char_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.U1_CH); } else if (expr_type == TypeManager.short_type){ // // From short to sbyte, byte, ushort, uint, ulong, char // if (real_target_type == TypeManager.sbyte_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I2_I1); if (real_target_type == TypeManager.byte_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I2_U1); if (real_target_type == TypeManager.ushort_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I2_U2); if (real_target_type == TypeManager.uint32_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I2_U4); if (real_target_type == TypeManager.uint64_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I2_U8); if (real_target_type == TypeManager.char_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I2_CH); } else if (expr_type == TypeManager.ushort_type){ // // From ushort to sbyte, byte, short, char // if (real_target_type == TypeManager.sbyte_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.U2_I1); if (real_target_type == TypeManager.byte_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.U2_U1); if (real_target_type == TypeManager.short_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.U2_I2); if (real_target_type == TypeManager.char_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.U2_CH); } else if (expr_type == TypeManager.int32_type){ // // From int to sbyte, byte, short, ushort, uint, ulong, char // if (real_target_type == TypeManager.sbyte_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I4_I1); if (real_target_type == TypeManager.byte_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I4_U1); if (real_target_type == TypeManager.short_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I4_I2); if (real_target_type == TypeManager.ushort_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I4_U2); if (real_target_type == TypeManager.uint32_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I4_U4); if (real_target_type == TypeManager.uint64_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I4_U8); if (real_target_type == TypeManager.char_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I4_CH); } else if (expr_type == TypeManager.uint32_type){ // // From uint to sbyte, byte, short, ushort, int, char // if (real_target_type == TypeManager.sbyte_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.U4_I1); if (real_target_type == TypeManager.byte_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.U4_U1); if (real_target_type == TypeManager.short_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.U4_I2); if (real_target_type == TypeManager.ushort_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.U4_U2); if (real_target_type == TypeManager.int32_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.U4_I4); if (real_target_type == TypeManager.char_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.U4_CH); } else if (expr_type == TypeManager.int64_type){ // // From long to sbyte, byte, short, ushort, int, uint, ulong, char // if (real_target_type == TypeManager.sbyte_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I8_I1); if (real_target_type == TypeManager.byte_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I8_U1); if (real_target_type == TypeManager.short_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I8_I2); if (real_target_type == TypeManager.ushort_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I8_U2); if (real_target_type == TypeManager.int32_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I8_I4); if (real_target_type == TypeManager.uint32_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I8_U4); if (real_target_type == TypeManager.uint64_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I8_U8); if (real_target_type == TypeManager.char_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.I8_CH); } else if (expr_type == TypeManager.uint64_type){ // // From ulong to sbyte, byte, short, ushort, int, uint, long, char // if (real_target_type == TypeManager.sbyte_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.U8_I1); if (real_target_type == TypeManager.byte_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.U8_U1); if (real_target_type == TypeManager.short_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.U8_I2); if (real_target_type == TypeManager.ushort_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.U8_U2); if (real_target_type == TypeManager.int32_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.U8_I4); if (real_target_type == TypeManager.uint32_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.U8_U4); if (real_target_type == TypeManager.int64_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.U8_I8); if (real_target_type == TypeManager.char_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.U8_CH); } else if (expr_type == TypeManager.char_type){ // // From char to sbyte, byte, short // if (real_target_type == TypeManager.sbyte_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.CH_I1); if (real_target_type == TypeManager.byte_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.CH_U1); if (real_target_type == TypeManager.short_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.CH_I2); } else if (expr_type == TypeManager.float_type){ // // From float to sbyte, byte, short, // ushort, int, uint, long, ulong, char // or decimal // if (real_target_type == TypeManager.sbyte_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.R4_I1); if (real_target_type == TypeManager.byte_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.R4_U1); if (real_target_type == TypeManager.short_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.R4_I2); if (real_target_type == TypeManager.ushort_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.R4_U2); if (real_target_type == TypeManager.int32_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.R4_I4); if (real_target_type == TypeManager.uint32_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.R4_U4); if (real_target_type == TypeManager.int64_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.R4_I8); if (real_target_type == TypeManager.uint64_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.R4_U8); if (real_target_type == TypeManager.char_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.R4_CH); } else if (expr_type == TypeManager.double_type){ // // From double to byte, byte, short, // ushort, int, uint, long, ulong, // char, float or decimal // if (real_target_type == TypeManager.sbyte_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.R8_I1); if (real_target_type == TypeManager.byte_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.R8_U1); if (real_target_type == TypeManager.short_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.R8_I2); if (real_target_type == TypeManager.ushort_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.R8_U2); if (real_target_type == TypeManager.int32_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.R8_I4); if (real_target_type == TypeManager.uint32_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.R8_U4); if (real_target_type == TypeManager.int64_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.R8_I8); if (real_target_type == TypeManager.uint64_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.R8_U8); if (real_target_type == TypeManager.char_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.R8_CH); if (real_target_type == TypeManager.float_type) return new ConvCast (ec, expr, target_type, ConvCast.Mode.R8_R4); } // decimal is taken care of by the op_Explicit methods. return null; } /// <summary> /// Returns whether an explicit reference conversion can be performed /// from source_type to target_type /// </summary> public static bool ExplicitReferenceConversionExists (Type source_type, Type target_type) { bool target_is_value_type = target_type.IsValueType; if (source_type == target_type) return true; // // From object to any reference type // if (source_type == TypeManager.object_type && !target_is_value_type) return true; // // From any class S to any class-type T, provided S is a base class of T // if (target_type.IsSubclassOf (source_type)) return true; // // From any interface type S to any interface T provided S is not derived from T // if (source_type.IsInterface && target_type.IsInterface){ if (!target_type.IsSubclassOf (source_type)) return true; } // // From any class type S to any interface T, provided S is not sealed // and provided S does not implement T. // if (target_type.IsInterface && !source_type.IsSealed && !TypeManager.ImplementsInterface (source_type, target_type)) return true; // // From any interface-type S to to any class type T, provided T is not // sealed, or provided T implements S. // if (source_type.IsInterface && (!target_type.IsSealed || TypeManager.ImplementsInterface (target_type, source_type))) return true; // From an array type S with an element type Se to an array type T with an // element type Te provided all the following are true: // * S and T differe only in element type, in other words, S and T // have the same number of dimensions. // * Both Se and Te are reference types // * An explicit referenc conversions exist from Se to Te // if (source_type.IsArray && target_type.IsArray) { if (source_type.GetArrayRank () == target_type.GetArrayRank ()) { Type source_element_type = TypeManager.GetElementType (source_type); Type target_element_type = TypeManager.GetElementType (target_type); if (!source_element_type.IsValueType && !target_element_type.IsValueType) if (ExplicitReferenceConversionExists (source_element_type, target_element_type)) return true; } } // From System.Array to any array-type if (source_type == TypeManager.array_type && target_type.IsArray){ return true; } // // From System delegate to any delegate-type // if (source_type == TypeManager.delegate_type && target_type.IsSubclassOf (TypeManager.delegate_type)) return true; // // From ICloneable to Array or Delegate types // if (source_type == TypeManager.icloneable_type && (target_type == TypeManager.array_type || target_type == TypeManager.delegate_type)) return true; return false; } /// <summary> /// Implements Explicit Reference conversions /// </summary> static Expression ExplicitReferenceConversion (Expression source, Type target_type) { Type source_type = source.Type; bool target_is_value_type = target_type.IsValueType; // // From object to any reference type // if (source_type == TypeManager.object_type && !target_is_value_type) return new ClassCast (source, target_type); // // From any class S to any class-type T, provided S is a base class of T // if (target_type.IsSubclassOf (source_type)) return new ClassCast (source, target_type); // // From any interface type S to any interface T provided S is not derived from T // if (source_type.IsInterface && target_type.IsInterface){ if (TypeManager.ImplementsInterface (source_type, target_type)) return null; else return new ClassCast (source, target_type); } // // From any class type S to any interface T, provides S is not sealed // and provided S does not implement T. // if (target_type.IsInterface && !source_type.IsSealed) { if (TypeManager.ImplementsInterface (source_type, target_type)) return null; else return new ClassCast (source, target_type); } // // From any interface-type S to to any class type T, provided T is not // sealed, or provided T implements S. // if (source_type.IsInterface) { if (!target_type.IsSealed || TypeManager.ImplementsInterface (target_type, source_type)) { if (target_type.IsClass) return new ClassCast (source, target_type); else return new UnboxCast (source, target_type); } return null; } // From an array type S with an element type Se to an array type T with an // element type Te provided all the following are true: // * S and T differe only in element type, in other words, S and T // have the same number of dimensions. // * Both Se and Te are reference types // * An explicit referenc conversions exist from Se to Te // if (source_type.IsArray && target_type.IsArray) { if (source_type.GetArrayRank () == target_type.GetArrayRank ()) { Type source_element_type = TypeManager.GetElementType (source_type); Type target_element_type = TypeManager.GetElementType (target_type); if (!source_element_type.IsValueType && !target_element_type.IsValueType) if (ExplicitReferenceConversionExists (source_element_type, target_element_type)) return new ClassCast (source, target_type); } } // From System.Array to any array-type if (source_type == TypeManager.array_type && target_type.IsArray) { return new ClassCast (source, target_type); } // // From System delegate to any delegate-type // if (source_type == TypeManager.delegate_type && target_type.IsSubclassOf (TypeManager.delegate_type)) return new ClassCast (source, target_type); // // From ICloneable to Array or Delegate types // if (source_type == TypeManager.icloneable_type && (target_type == TypeManager.array_type || target_type == TypeManager.delegate_type)) return new ClassCast (source, target_type); return null; } /// <summary> /// Performs an explicit conversion of the expression `expr' whose /// type is expr.Type to `target_type'. /// </summary> static public Expression ExplicitConversion (EmitContext ec, Expression expr, Type target_type, Location loc) { Type expr_type = expr.Type; Type original_expr_type = expr_type; if (expr_type.IsSubclassOf (TypeManager.enum_type)){ if (target_type == TypeManager.enum_type || target_type == TypeManager.object_type) { if (expr is EnumConstant) expr = ((EnumConstant) expr).Child; // We really need all these casts here .... :-( expr = new BoxedCast (new EmptyCast (expr, expr_type)); return new EmptyCast (expr, target_type); } else if ((expr_type == TypeManager.enum_type) && target_type.IsValueType && target_type.IsSubclassOf (TypeManager.enum_type)) return new UnboxCast (expr, target_type); // // Notice that we have kept the expr_type unmodified, which is only // used later on to if (expr is EnumConstant) expr = ((EnumConstant) expr).Child; else expr = new EmptyCast (expr, TypeManager.EnumToUnderlying (expr_type)); expr_type = expr.Type; } Expression ne = ImplicitConversionStandard (ec, expr, target_type, loc); if (ne != null) return ne; ne = ExplicitNumericConversion (ec, expr, target_type, loc); if (ne != null) return ne; // // Unboxing conversion. // if (expr_type == TypeManager.object_type && target_type.IsValueType){ if (expr is NullLiteral){ Report.Error (37, "Cannot convert null to value type `" + TypeManager.CSharpName (expr_type) + "'"); return null; } return new UnboxCast (expr, target_type); } ne = ExplicitReferenceConversion (expr, target_type); if (ne != null) return ne; if (ec.InUnsafe){ if (target_type.IsPointer){ if (expr_type.IsPointer) return new EmptyCast (expr, target_type); if (expr_type == TypeManager.sbyte_type || expr_type == TypeManager.byte_type || expr_type == TypeManager.short_type || expr_type == TypeManager.ushort_type || expr_type == TypeManager.int32_type || expr_type == TypeManager.uint32_type || expr_type == TypeManager.uint64_type || expr_type == TypeManager.int64_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_U); } if (expr_type.IsPointer){ Expression e = null; if (target_type == TypeManager.sbyte_type) e = new OpcodeCast (expr, target_type, OpCodes.Conv_I1); else if (target_type == TypeManager.byte_type) e = new OpcodeCast (expr, target_type, OpCodes.Conv_U1); else if (target_type == TypeManager.short_type) e = new OpcodeCast (expr, target_type, OpCodes.Conv_I2); else if (target_type == TypeManager.ushort_type) e = new OpcodeCast (expr, target_type, OpCodes.Conv_U2); else if (target_type == TypeManager.int32_type) e = new OpcodeCast (expr, target_type, OpCodes.Conv_I4); else if (target_type == TypeManager.uint32_type) e = new OpcodeCast (expr, target_type, OpCodes.Conv_U4); else if (target_type == TypeManager.uint64_type) e = new OpcodeCast (expr, target_type, OpCodes.Conv_U8); else if (target_type == TypeManager.int64_type){ e = new OpcodeCast (expr, target_type, OpCodes.Conv_I8); } if (e != null){ Expression ci, ce; ci = ImplicitConversionStandard (ec, e, target_type, loc); if (ci != null) return ci; ce = ExplicitNumericConversion (ec, e, target_type, loc); if (ce != null) return ce; // // We should always be able to go from an uint32 // implicitly or explicitly to the other integral // types // throw new Exception ("Internal compiler error"); } } } ne = ExplicitUserConversion (ec, expr, target_type, loc); if (ne != null) return ne; Error_CannotConvertType (loc, original_expr_type, target_type); return null; } /// <summary> /// Same as ExplicitConversion, only it doesn't include user defined conversions /// </summary> static public Expression ExplicitConversionStandard (EmitContext ec, Expression expr, Type target_type, Location l) { Expression ne = ImplicitConversionStandard (ec, expr, target_type, l); if (ne != null) return ne; ne = ExplicitNumericConversion (ec, expr, target_type, l); if (ne != null) return ne; ne = ExplicitReferenceConversion (expr, target_type); if (ne != null) return ne; Error_CannotConvertType (l, expr.Type, target_type); return null; } } } --- NEW FILE --- // // flowanalyis.cs: The control flow analysis cod... [truncated message content] |
From: Gaurav V. <mas...@us...> - 2003-04-10 07:10:41
|
Update of /cvsroot/csdoc/csdoc/src/csdoc In directory sc8-pr-cvs1:/tmp/cvs-serv19011 Modified Files: AssemblyObjectNames.cs ChangeLog decl.cs namespace.cs Log Message: 2003-04-10 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * decl.cs, * namespace.cs : Added more support for CS0101 bug. Can now report an error is a class One::Two exists when namespace One.Two is already defined and vice-versa. Index: AssemblyObjectNames.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/AssemblyObjectNames.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AssemblyObjectNames.cs 10 Apr 2003 05:14:44 -0000 1.1 +++ AssemblyObjectNames.cs 10 Apr 2003 07:10:36 -0000 1.2 @@ -1,142 +1,158 @@ -/** - * - * Project : Master C# Documentation Generator - * URL : http://csdoc.sourceforge.net - * Namespace : Mono.CSharp - * Class : AssemblyObjectNames - * Author : Gaurav Vaish - * - * Copyright : (C) 2002-2003, with Gaurav Vaish - */ - -using System; -using System.Collections; - -namespace Mono.CSharp -{ - public class AssemblyObjectNames - { - private static AssemblyObjectNames root = - new AssemblyObjectNames(); - private string thisName; - private AssemblyObjectNames[] children; - - private AssemblyObjectNames() - { - this.thisName = String.Empty; - this.children = null; - } - - private AssemblyObjectNames(string fullName) - { - int colon = fullName.IndexOf('.'); - string first = (colon == -1 ? - fullName : fullName.Substring(0, colon)); - string remainder = (colon == -1 ? - String.Empty : fullName.Substring(colon + 1)); - this.thisName = first; - if(colon > 0) - { - AddChild(remainder); - } - } - - public AssemblyObjectNames Root - { - get - { - return root; - } - } - - public string Name - { - get - { - return this.thisName; - } - } - - public AssemblyObjectNames[] Children - { - get - { - return this.children; - } - } - - // false == could not add. Name already defined - public bool AddChild(string fullName) - { - if(IsDefined(fullName)) - return false; - return Root.AddChild(ref Root.children, fullName); - } - - private bool AddChild(ref AssemblyObjectNames[] names, - string subName) - { - int colon = subName.IndexOf('.'); - string first = (colon == -1 ? - subName : subName.Substring(0, colon)); - string remainder = (colon == -1 ? - String.Empty : subName.Substring(colon + 1)); - int addIndex = -1; - bool existed = false; - if(names == null) - { - names = new AssemblyObjectNames[1]; - names[0] = new AssemblyObjectNames(); - names[0].thisName = first; - names[0].children = null; - addIndex = 0; - } else - { - for(int index = 0; index < names.Length; index++) - { - if(names[index].thisName == first) - { - addIndex = index; - existed = true; - break; - } - } - if(!existed) - { - int len = names.Length; - AssemblyObjectNames[] newNames = - new AssemblyObjectNames[len]; - Array.Copy(names, newNames, len); - names = new AssemblyObjectNames[len + 1]; - Array.Copy(newNames, names, len); - names[len] = new AssemblyObjectNames(); - names[len].thisName = first; - names[len].children = null; - addIndex = len; - } - } - if(remainder == String.Empty) - { - return !existed; - } - - return AddChild(ref names[addIndex].children, remainder); - } - - private static string GetBasename(string nsName, - int level) - { - string[] split = nsName.Split(new char[] { '.' }); - if(level < split.Length) - { - return split[level]; - } - return String.Empty; - } - - private static bool IsDefined(string fullName) - { - throw new NotImplementedException(); - } - } -} +/** + * + * Project : Master C# Documentation Generator + * URL : http://csdoc.sourceforge.net + * Namespace : Mono.CSharp + * Class : AssemblyObjectNames + * Author : Gaurav Vaish + * + * Copyright : (C) 2002-2003, with Gaurav Vaish + */ + +using System; +using System.Collections; + +namespace Mono.CSharp +{ + public class AssemblyObjectNames + { + private static AssemblyObjectNames root = + new AssemblyObjectNames(); + private string thisName; + private Location location; + private AssemblyObjectNames[] children; + private bool isNamespace; + + private AssemblyObjectNames() + { + this.thisName = String.Empty; + this.children = null; + } + + public static AssemblyObjectNames Root + { + get + { + return root; + } + } + + public bool IsNamespace + { + get + { + return this.isNamespace; + } + } + + public Location Location + { + get + { + return this.location; + } + } + + public string Name + { + get + { + return this.thisName; + } + } + + public AssemblyObjectNames[] Children + { + get + { + return this.children; + } + } + + // false == could not add. Name already defined + public bool AddChild(string fullName, ref Location location, + bool isNamespace) + { + return Root.AddChild(ref Root.children, ref location, + fullName, isNamespace); + } + + private bool AddChild(ref AssemblyObjectNames[] names, + ref Location location, + string subName, bool isNamespace) + { + int colon = subName.IndexOf('.'); + string first = (colon == -1 ? + subName : subName.Substring(0, colon)); + string remainder = (colon == -1 ? + String.Empty : subName.Substring(colon + 1)); + int addIndex = -1; + bool existed = false; + if(names == null) + { + names = new AssemblyObjectNames[1]; + names[0] = new AssemblyObjectNames(); + names[0].thisName = first; + names[0].children = null; + names[0].isNamespace = isNamespace; + names[0].location = location; + addIndex = 0; + } else + { + for(int index = 0; index < names.Length; index++) + { + if(names[index].thisName == first) + { + addIndex = index; + existed = true; + break; + } + } + if(!existed) + { + int len = names.Length; + AssemblyObjectNames[] newNames = + new AssemblyObjectNames[len]; + Array.Copy(names, newNames, len); + names = new AssemblyObjectNames[len + 1]; + Array.Copy(newNames, names, len); + names[len] = new AssemblyObjectNames(); + names[len].thisName = first; + names[len].children = null; + names[len].isNamespace = isNamespace; + names[len].location = location; + addIndex = len; + } + } + if(remainder == String.Empty) + { + if(existed) + { + location = names[addIndex].location; + return (names[addIndex].isNamespace && isNamespace); + } + return true; + } + + return AddChild(ref names[addIndex].children, + ref location, + remainder, isNamespace); + } + + private static string GetBasename(string nsName, + int level) + { + string[] split = nsName.Split(new char[] { '.' }); + if(level < split.Length) + { + return split[level]; + } + return String.Empty; + } + + private static bool IsDefined(string fullName) + { + throw new NotImplementedException(); + } + } +} Index: ChangeLog =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/ChangeLog,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- ChangeLog 10 Apr 2003 05:14:44 -0000 1.23 +++ ChangeLog 10 Apr 2003 07:10:36 -0000 1.24 @@ -1,6 +1,14 @@ 2003-04-10 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + * decl.cs, + * namespace.cs : Added more support for CS0101 bug. + Can now report an error is a class + One::Two exists when namespace One.Two + is already defined and vice-versa. + +2003-04-10 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + * makefile : Modified doc target to build binary as $(BINARY) instead of default driver.exe : Use AssemblyObjectNames.cs Index: decl.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/decl.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- decl.cs 24 Feb 2003 08:33:51 -0000 1.2 +++ decl.cs 10 Apr 2003 07:10:36 -0000 1.3 @@ -300,6 +300,11 @@ Basename = name.Substring (1 + name.LastIndexOf ('.')); defined_names = new Hashtable (); this.parent = parent; + if(name.Trim().Length > 0) + { + if(!AssemblyObjectNames.Root.AddChild(name, ref l, false)) + Report.Error(101, l, "Failed to add \"" + name + "\""); + } } /// <summary> Index: namespace.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/namespace.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- namespace.cs 8 Apr 2003 06:24:42 -0000 1.2 +++ namespace.cs 10 Apr 2003 07:10:36 -0000 1.3 @@ -72,6 +72,10 @@ this.parent = parent; all_namespaces.Add (this); + Location l = new Location(-1); + if(!AssemblyObjectNames.Root.AddChild(name, ref l, true)) + Report.Error(0101, l, "Failed to add namespace: " + name); + //Console.WriteLine("Failed to add namespace: " + name); } /// <summary> |
From: Gaurav V. <mas...@us...> - 2003-04-10 05:16:07
|
Update of /cvsroot/csdoc/csdoc/src/tests In directory sc8-pr-cvs1:/tmp/cvs-serv9443 Modified Files: ChangeLog test_10.cs Log Message: 2003-04-08 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * test_10.cs : Correct the ending summary-tag. Index: ChangeLog =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/tests/ChangeLog,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- ChangeLog 8 Apr 2003 06:22:09 -0000 1.17 +++ ChangeLog 10 Apr 2003 05:16:02 -0000 1.18 @@ -1,4 +1,8 @@ +2003-04-08 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + + * test_10.cs : Correct the ending summary-tag. + 2003-04-07 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * test_24.cs : More than one namespace. Index: test_10.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/tests/test_10.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- test_10.cs 21 Feb 2003 07:09:46 -0000 1.1 +++ test_10.cs 10 Apr 2003 05:16:03 -0000 1.2 @@ -1,7 +1,7 @@ using System; /** - * <summary>CSDoc.Test/summary> + * <summary>CSDoc.Test</summary> */ namespace CSDoc.Test { |
From: Gaurav V. <mas...@us...> - 2003-04-10 05:14:47
|
Update of /cvsroot/csdoc/csdoc/src/csdoc In directory sc8-pr-cvs1:/tmp/cvs-serv9208 Modified Files: cs-tokenizer.cs driver.cs makefile ChangeLog Added Files: AssemblyObjectNames.cs Log Message: 2003-04-10 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * makefile : Modified doc target to build binary as $(BINARY) instead of default driver.exe : Use AssemblyObjectNames.cs : clean now also removes *.xml * AssemblyObjectNames.cs : Added new class. To take care of all the defined names. * cs-tokenizer.cs : trim the commentString before returing. --- NEW FILE --- /** * * Project : Master C# Documentation Generator * URL : http://csdoc.sourceforge.net * Namespace : Mono.CSharp * Class : AssemblyObjectNames * Author : Gaurav Vaish * * Copyright : (C) 2002-2003, with Gaurav Vaish */ using System; using System.Collections; namespace Mono.CSharp { public class AssemblyObjectNames { private static AssemblyObjectNames root = new AssemblyObjectNames(); private string thisName; private AssemblyObjectNames[] children; private AssemblyObjectNames() { this.thisName = String.Empty; this.children = null; } private AssemblyObjectNames(string fullName) { int colon = fullName.IndexOf('.'); string first = (colon == -1 ? fullName : fullName.Substring(0, colon)); string remainder = (colon == -1 ? String.Empty : fullName.Substring(colon + 1)); this.thisName = first; if(colon > 0) { AddChild(remainder); } } public AssemblyObjectNames Root { get { return root; } } public string Name { get { return this.thisName; } } public AssemblyObjectNames[] Children { get { return this.children; } } // false == could not add. Name already defined public bool AddChild(string fullName) { if(IsDefined(fullName)) return false; return Root.AddChild(ref Root.children, fullName); } private bool AddChild(ref AssemblyObjectNames[] names, string subName) { int colon = subName.IndexOf('.'); string first = (colon == -1 ? subName : subName.Substring(0, colon)); string remainder = (colon == -1 ? String.Empty : subName.Substring(colon + 1)); int addIndex = -1; bool existed = false; if(names == null) { names = new AssemblyObjectNames[1]; names[0] = new AssemblyObjectNames(); names[0].thisName = first; names[0].children = null; addIndex = 0; } else { for(int index = 0; index < names.Length; index++) { if(names[index].thisName == first) { addIndex = index; existed = true; break; } } if(!existed) { int len = names.Length; AssemblyObjectNames[] newNames = new AssemblyObjectNames[len]; Array.Copy(names, newNames, len); names = new AssemblyObjectNames[len + 1]; Array.Copy(newNames, names, len); names[len] = new AssemblyObjectNames(); names[len].thisName = first; names[len].children = null; addIndex = len; } } if(remainder == String.Empty) { return !existed; } return AddChild(ref names[addIndex].children, remainder); } private static string GetBasename(string nsName, int level) { string[] split = nsName.Split(new char[] { '.' }); if(level < split.Length) { return split[level]; } return String.Empty; } private static bool IsDefined(string fullName) { throw new NotImplementedException(); } } } Index: cs-tokenizer.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/cs-tokenizer.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- cs-tokenizer.cs 27 Mar 2003 17:50:52 -0000 1.8 +++ cs-tokenizer.cs 10 Apr 2003 05:14:44 -0000 1.9 @@ -74,7 +74,7 @@ public string GetDocs() { - string retVal = commentString; + string retVal = commentString.Trim(); SaveDocument(); return retVal; } Index: driver.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/driver.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- driver.cs 8 Apr 2003 06:24:42 -0000 1.10 +++ driver.cs 10 Apr 2003 05:14:44 -0000 1.11 @@ -1,1171 +1,1193 @@ -// -// Author: Gaurav Vaish <mas...@us...> -// -// Licensed under the terms of the GNU GPL. -// -// (C) 2003 Gaurav Vaish -// Original Authors: Miguel, Ravi, Martin -// - -namespace Mono.CSharp -{ - using System; - using System.Reflection; - using System.Reflection.Emit; - using System.Collections; - using System.IO; - using System.Text; - using System.Globalization; - using Mono.Languages; - - enum Target { - Library, Exe, Module, WinExe - }; - - /// <summary> - /// The compiler driver. - /// </summary> - public class Driver - { - - // - // Assemblies references to be linked. Initialized with - // mscorlib.dll here. - static ArrayList references; - - // - // If any of these fail, we ignore the problem. This is so - // that we can list all the assemblies in Windows and not fail - // if they are missing on Linux. - // - static ArrayList soft_references; - - // Lookup paths - static ArrayList link_paths; - - // Whether we want Yacc to output its progress - static bool yacc_verbose = false; - - static string first_source; - - //static Target target = Target.Exe; - //static string target_ext = ".exe"; - - static bool want_debugging_support = false; - - //static bool parse_only = false; - //static bool timestamps = false; - //static bool pause = false; - - // - // Whether to load the initial config file (what CSC.RSP has by default) - // - static bool load_default_config = true; - - static Hashtable response_file_list; - - // - // A list of resource files - // - static ArrayList resources; - static ArrayList embedded_resources; - - // - // An array of the defines from the command line - // - static ArrayList defines; - - // - // Output file - // - static string output_file = null; - - // - // Last time we took the time - // - static DateTime last_time, first_time; - - // - // Encoding: ISO-Latin1 is 28591 - // - static Encoding encoding; - - // - // Whether the user has specified a different encoder manually - // - static bool using_default_encoder = true; - - public static void ShowTime(string msg) - { - DateTime now = DateTime.Now; - TimeSpan span = now - last_time; - last_time = now; - - Console.WriteLine ( - "[{0:00}:{1:000}] {2}", - (int) span.TotalSeconds, span.Milliseconds, msg); - } - - public static void ShowTotalTime(string msg) - { - DateTime now = DateTime.Now; - TimeSpan span = now - first_time; - last_time = now; - - Console.WriteLine ( - "[{0:00}:{1:000}] {2}", - (int) span.TotalSeconds, span.Milliseconds, msg); - } - - // MonoTODO("Change error code for aborted compilation to something reasonable")] - static void parse(SourceFile file) - { - CSharpParser parser; - Stream input; - - try - { - input = File.OpenRead(file.Name); - } catch - { - Report.Error(2001, "Source file '" + file.Name + "' could not be opened"); - return; - } - - StreamReader reader = new StreamReader(input, encoding, using_default_encoder); - - parser = new CSharpParser (reader, file, defines); - parser.yacc_verbose = yacc_verbose; - try - { - parser.parse(); - } catch(Exception ex) - { - Report.Error(666, "Compilation aborted: " + ex); - } finally { - input.Close (); - } - } - - static void Usage() - { - // Doclet defaultDoclet = new CSDoclet(...); - // string options = defaultDoclet.UsageString(); - Console.WriteLine("" + - "C# Document Generator, (C) 2003 Gaurav Vaish\n" + - "\n" + - "usage: \n" + - "csdoc [options] [namespace-names] [sourcefiles] [@files] \n" + - " -overview <file> Read overview documentation from HTML file\n" + - " -public Show only public classes and members\n" + - " -protected Show protected/public classes and members\n" + - " -internal Show internal/protected/public classes and members\n" + - " -private Show all classes and members\n" + - " -doclet <class> Generate output via alternate doclet\n" + - //" -verbose Be verbose of what is being done\n" + - //" --reference:ASS Reference the specified assembly\n" + - " -r:ASS Same as --reference\n" + - " --help Display command line options and exit\n" + - " --about About the CSDoc Document Generator\n" + - "\n" + - "Resources:\n" + - " --linkresource FILE[,ID] Links FILE as a resource\n" + - " --resource FILE[,ID] Embed FILE as a resource\n" + - "\n" + - "Options can be of the form -option or /option" + /* options */ - ""); - } - - static void About() - { - Console.WriteLine("" + - " The CSDoc Document Generator is (C) 2003, Gaurav Vaish.\n" + - " The source code is released under the terms of the GNU GPL.\n" + - "\n" + - " For more information on CSDoc, visit the website:\n" + - " http://csdoc.sourceforge.net\n" + - "\n" + - " The application is mastermind of Gaurav Vaish.\n" + - ""); - } - - public static int Main(string[] args) - { - bool ok = MainDriver(args); - - if (ok && Report.Errors == 0) - { - Console.Write("Compilation succeeded"); - if(Report.Warnings > 0) - { - Console.Write(" - {0} warning(s)", Report.Warnings); - } - Console.WriteLine(); - return 0; - } else - { - Console.WriteLine("Compilation failed: {0} error(s), {1} warnings", - Report.Errors, Report.Warnings); - return 1; - } - } - - static public void LoadAssembly(string assembly, bool soft) - { - Assembly a; - string total_log = ""; - - try - { - char[] path_chars = { '/', '\\', '.' }; - - if (assembly.IndexOfAny(path_chars) != -1) - { - a = Assembly.LoadFrom(assembly); - } else - { - a = Assembly.Load(assembly); - } - TypeManager.AddAssembly(a); - - } catch(FileNotFoundException) - { - foreach (string dir in link_paths) - { - string full_path = Path.Combine(dir, assembly); - if(!assembly.EndsWith(".dll")) - full_path += ".dll"; - - try - { - a = Assembly.LoadFrom(full_path); - TypeManager.AddAssembly(a); - return; - } catch (FileNotFoundException ff) - { - total_log += ff.FusionLog; - continue; - } - } - if(!soft) - { - Report.Error(6, "Cannot find assembly `" + assembly + "'" ); - Console.WriteLine("Log: \n" + total_log); - } - } catch(BadImageFormatException f) - { - Report.Error(6, "Cannot load assembly (bad file format)" + f.FusionLog); - } catch(FileLoadException f) - { - Report.Error(6, "Cannot load assembly " + f.FusionLog); - } catch(ArgumentNullException) - { - Report.Error(6, "Cannot load assembly (null argument)"); - } - } - - /// <summary> - /// Loads all assemblies referenced on the command line - /// </summary> - static public void LoadReferences() - { - foreach(string r in references) - LoadAssembly(r, false); - - foreach(string r in soft_references) - LoadAssembly(r, true); - - return; - } - - static void SetupDefaultDefines() - { - defines = new ArrayList (); - defines.Add("__MonoCS__"); - defines.Add("__MCSDoc__"); - } - - static string [] LoadArgs(string file) - { - StreamReader f; - ArrayList args = new ArrayList(); - string line; - try - { - f = new StreamReader(file); - } catch - { - return null; - } - - StringBuilder sb = new StringBuilder (); - - while((line = f.ReadLine()) != null) - { - int t = line.Length; - - for (int i = 0; i < t; i++) - { - char c = line [i]; - - if (c == '"' || c == '\'') - { - char end = c; - - for(i++; i < t; i++) - { - c = line [i]; - - if (c == end) - break; - sb.Append (c); - } - } else if (c == ' ') - { - if (sb.Length > 0) - { - args.Add (sb.ToString ()); - sb.Length = 0; - } - } else - sb.Append (c); - } - if (sb.Length > 0) - { - args.Add (sb.ToString ()); - sb.Length = 0; - } - } - - string[] ret_value = new string[args.Count]; - args.CopyTo(ret_value, 0); - - return ret_value; - } - - // - // Returns the directory where the system assemblies are installed - // - static string GetSystemDir() - { - Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); - - foreach (Assembly a in assemblies) - { - string codebase = a.Location; - if(codebase.EndsWith ("corlib.dll")) - { - return codebase.Substring(0, codebase.LastIndexOf(System.IO.Path.DirectorySeparatorChar)); - } - } - - Report.Error (-15, "Can not compute my system path"); - return ""; - } - - // - // Given a path specification, splits the path from the file/pattern - // - static void SplitPathAndPattern(string spec, out string path, out string pattern) - { - int p = spec.LastIndexOf("/"); - if (p != -1){ - // - // Windows does not like /file.cs, switch that to: - // "\", "file.cs" - // - if (p == 0) - { - path = "\\"; - pattern = spec.Substring(1); - } else - { - path = spec.Substring(0, p); - pattern = spec.Substring(p + 1); - } - return; - } - - p = spec.LastIndexOf("\\"); - if (p != -1) - { - path = spec.Substring(0, p); - pattern = spec.Substring(p + 1); - return; - } - - path = "."; - pattern = spec; - } - - static void ProcessFile(string f) - { - if (first_source == null) - first_source = f; - - Location.AddFile(f); - } - - static void ProcessFiles() - { - Location.Initialize(); - - foreach(SourceFile file in Location.SourceFiles) - { - parse(file); - } - } - - static void CompileFiles(string spec, bool recurse) - { - string path, pattern; - - SplitPathAndPattern(spec, out path, out pattern); - if(pattern.IndexOf("*") == -1) - { - ProcessFile(spec); - return; - } - - string[] files = null; - try - { - files = Directory.GetFiles (path, pattern); - } catch (System.IO.DirectoryNotFoundException) - { - Report.Error (2001, "Source file `" + spec + "' could not be found"); - return; - } catch (System.IO.IOException) - { - Report.Error (2001, "Source file `" + spec + "' could not be found"); - return; - } - - foreach(string f in files) - { - ProcessFile(f); - } - - if(!recurse) - return; - - string[] dirs = null; - - try - { - dirs = Directory.GetDirectories (path); - } catch { } - - foreach(string d in dirs) - { - // Don't include path in this string, as each - // directory entry already does - CompileFiles (d + "/" + pattern, true); - } - } - - static void DefineDefaultConfig() - { - // - // For now the "default config" is harcoded into the compiler - // we can move this outside later - // - string[] default_config = - { - "System", - "System.Xml", -#if false - // - // Is it worth pre-loading all this stuff? - // - "Accessibility", - "System.Configuration.Install", - "System.Data", - "System.Design", - "System.DirectoryServices", - "System.Drawing.Design", - "System.Drawing", - "System.EnterpriseServices", - "System.Management", - "System.Messaging", - "System.Runtime.Remoting", - "System.Runtime.Serialization.Formatters.Soap", - "System.Security", - "System.ServiceProcess", - "System.Web", - "System.Web.RegularExpressions", - "System.Web.Services", - "System.Windows.Forms" -#endif - }; - - int p = 0; - foreach(string def in default_config) - soft_references.Insert(p++, def); - } - - static void SetOutputFile(string name) - { - output_file = name; - } - - static void SetWarningLevel(string s) - { - int level = 0; - - try - { - level = Int32.Parse(s); - } catch - { - Report.Error(1900, "--wlevel requires an value from 0 to 4"); - Environment.Exit(1); - } - if (level < 0 || level > 4) - { - Report.Error(1900, "Warning level must be 0 to 4"); - Environment.Exit(1); - } else - RootContext.WarningLevel = level; - } - - static void Version() - { - string version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); - Console.WriteLine("C# Document Generator Version {0}", version); - Environment.Exit(0); - } - - // - // Currently handles the Unix-like command line options, but will be - // deprecated in favor of the CSCParseOption, which will also handle the - // options that start with a dash in the future. - // - static bool UnixParseOption(string arg, ref string [] args, ref int i) - { - switch (arg) - { - - case "--version": - Version(); - return true; - - case "/?": case "/h": case "/help": - case "--help": - Usage(); - Environment.Exit(0); - return true; - - case "--about": - About(); - Environment.Exit(0); - return true; - - case "--recurse": - if ((i + 1) >= args.Length) - { - Report.Error(5, "--recurse requires an argument"); - Environment.Exit(1); - } - CompileFiles(args [++i], true); - return true; - - case "--linkresource": - case "--linkres": - if((i + 1) >= args.Length) - { - Usage(); - Report.Error(5, "Missing argument to --linkres"); - Environment.Exit(1); - } - if (resources == null) - resources = new ArrayList(); - - resources.Add(args[++i]); - return true; - - case "--resource": - case "--res": - if ((i + 1) >= args.Length) - { - Usage(); - Report.Error(5, "Missing argument to --resource"); - Environment.Exit(1); - } - if (embedded_resources == null) - embedded_resources = new ArrayList(); - - embedded_resources.Add(args[++i]); - return true; - - } - return false; - } - - // - // Currently it is very basic option parsing, but eventually, this will - // be the complete option parser - // - static bool CSCParseOption(string option, ref string [] args, ref int i) - { - int idx = option.IndexOf(":"); - string arg, value; - - if (idx == -1) - { - arg = option; - value = ""; - } else - { - arg = option.Substring (0, idx); - value = option.Substring (idx + 1); - } - - switch(arg) - { - case "/nologo": - return true; - - case "/recurse": - if (value == ""){ - Report.Error (5, "/recurse requires an argument"); - Environment.Exit (1); - } - CompileFiles (value, true); - return true; - - case "/help": - case "/?": - Usage (); - Environment.Exit (0); - return true; - - case "/linkresource": - case "/linkres": - if ((i + 1) >= args.Length) - { - Usage(); - Report.Error(5, "Missing argument to --linkres"); - Environment.Exit(1); - } - if (resources == null) - resources = new ArrayList(); - - resources.Add(args[++i]); - return true; - - case "/resource": - case "/res": - if ((i + 1) >= args.Length) - { - Usage(); - Report.Error(5, "Missing argument to --resource"); - Environment.Exit(1); - } - if (embedded_resources == null) - embedded_resources = new ArrayList(); - - embedded_resources.Add(args[++i]); - return true; - - } - return false; - } - - /// <summary> - /// Parses the arguments, and drives the compilation - /// process. - /// </summary> - /// - /// <remarks> - /// TODO: Mostly structured to debug the compiler - /// now, needs to be turned into a real driver soon. - /// </remarks> - // [MonoTODO("Change error code for unknown argument to something reasonable")] - static bool MainDriver (string [] args) - { - int i; - bool parsing_options = true; - - try - { - encoding = Encoding.GetEncoding (28591); - } catch - { - Console.WriteLine ("Error: could not load encoding 28591, trying 1252"); - encoding = Encoding.GetEncoding (1252); - } - - references = new ArrayList(); - soft_references = new ArrayList(); - link_paths = new ArrayList(); - - SetupDefaultDefines(); - - // - // Setup defaults - // - // This is not required because Assembly.Load knows about this - // path. - // - - int argc = args.Length; - for (i = 0; i < argc; i++) - { - string arg = args [i]; - - if (arg.StartsWith ("@")){ - string [] new_args, extra_args; - string response_file = arg.Substring (1); - - if (response_file_list == null) - response_file_list = new Hashtable (); - - if (response_file_list.Contains (response_file)){ - Report.Error ( - 1515, "Response file `" + response_file + - "' specified multiple times"); - Environment.Exit (1); - } - - response_file_list.Add (response_file, response_file); - - extra_args = LoadArgs (response_file); - if (extra_args == null){ - Report.Error (2011, "Unable to open response file: " + - response_file); - return false; - } - - new_args = new string [extra_args.Length + argc]; - args.CopyTo (new_args, 0); - extra_args.CopyTo (new_args, argc); - args = new_args; - argc = new_args.Length; - continue; - } - - if (parsing_options){ - if (arg == "--"){ - parsing_options = false; - continue; - } - - if (arg.StartsWith ("-")){ - if (UnixParseOption (arg, ref args, ref i)) - continue; - - // Try a -CSCOPTION - string csc_opt = "/" + arg.Substring (1); - if (CSCParseOption (csc_opt, ref args, ref i)) - continue; - } else { - if (arg.StartsWith ("/")){ - if (CSCParseOption (arg, ref args, ref i)) - continue; - } - } - } - - CompileFiles(arg, false); - } - - ProcessFiles(); - - if (first_source == null){ - Report.Error (2008, "No files to compile were specified"); - return false; - } - - if (Report.Errors > 0) - return false; - - // - // Load Core Library for default compilation - // - if (RootContext.StdLib) - references.Insert (0, "mscorlib"); - - if (load_default_config) - DefineDefaultConfig(); - - if (Report.Errors > 0) - { - return false; - } - - // - // Load assemblies required - // - first_time = last_time = DateTime.Now; - - //ShowTime("Loading references"); - - link_paths.Add(GetSystemDir()); - LoadReferences(); - - //ShowTime(" References loaded"); - - if(Report.Errors > 0) - { - return false; - } - - // - // Quick hack - // - // Unfortunately, I'll need to keep this. :-(( - output_file = "MCSDoc.dll"; - - CodeGen.Init(output_file, null, want_debugging_support); - - TypeManager.AddModule(CodeGen.ModuleBuilder); - -#if false - DateTime start = DateTime.Now; - TypeManager.GetAssemblyNamespaces (output_file); - DateTime end = DateTime.Now; - //Console.WriteLine ("Loading namespaces: " + (end - start)); - start = DateTime.Now; - //TypeManager.GetAllTypes (); - end = DateTime.Now; - //Console.WriteLine ("Getting Types: " + (end - start)); -#endif - - // - // Before emitting, we need to get the core - // types emitted from the user defined types - // or from the system ones. - // - //ShowTime("Initializing Core Types"); - - if(!RootContext.StdLib) - { - RootContext.ResolveCore(); - if(Report.Errors > 0) - return false; - } - - TypeManager.InitCoreTypes(); - - //ShowTime(" Core Types done"); - - // - // The second pass of the compiler - // - //ShowTime("Resolving tree"); - - RootContext.ResolveTree(); - - //ShowTime("Populate tree"); - - if (!RootContext.StdLib) - RootContext.BootCorlib_PopulateCoreTypes(); - RootContext.PopulateTypes(); - RootContext.DefineTypes(); - - TypeManager.InitCodeHelpers(); - - if(Report.Errors > 0) - { - System.Console.WriteLine("Exiting after initializing code helpers..."); - return false; - } - - TypeContainer root = RootContext.Tree.Types; - Console.WriteLine("Root type: " + root.GetType()); - - ManageAttributeTypes(RootContext.AttributeTypes); - - ManageTypeContainer(root); - Console.WriteLine(); - -/* - ArrayList allns = Namespace.AllNamespaces; - foreach(Namespace nsallns in allns) - { - if(nsallns.Name.Trim().Length > 0) - { - Console.WriteLine("->" + nsallns.Name); - } - } -*/ -/* - Hashtable nss = RootContext.Tree.Namespaces; - //Hashtable nss = TypeManager.GetNamespaces(); - - Console.WriteLine("Total namespaces: " + nss.Count); - foreach(object objk in nss.Keys) - { - SourceFile sf = (SourceFile) objk; - object obj = nss[objk]; - Console.WriteLine("-> " + sf.Name); - //Console.WriteLine("\t-> " + ((Namespace)nss[sf.Name]).Name); - //Console.WriteLine("->" + obj.ToString()); - //Console.WriteLine("->" + obj.GetType()); - if(obj is Hashtable) - { - Hashtable ht = (Hashtable) obj; - foreach(object objht in ht.Keys) - { - Console.WriteLine("\t->" + ((Namespace)ht[objht]).Name); - } - } - } - Console.WriteLine(); -//*/ - - return Report.Errors == 0; - // - // The code generator - // - // Now, I don't need the rest of the stuff. -#if false - if (timestamps) - ShowTime ("Emitting code"); - ShowTotalTime ("Total so far"); - RootContext.EmitCode(); - if (timestamps) - ShowTime (" done"); - - if (Report.Errors > 0){ - return false; - } - - if (timestamps) - ShowTime ("Closing types"); - - if (RootContext.WarningLevel >= 4) - if (!Namespace.VerifyUsing ()) - return false; - - RootContext.CloseTypes (); - - PEFileKinds k = PEFileKinds.ConsoleApplication; - - if (target == Target.Library || target == Target.Module) - k = PEFileKinds.Dll; - else if (target == Target.Exe) - k = PEFileKinds.ConsoleApplication; - else if (target == Target.WinExe) - k = PEFileKinds.WindowApplication; - - if (target == Target.Exe || target == Target.WinExe){ - MethodInfo ep = RootContext.EntryPoint; - - if (ep == null){ - if (Report.Errors == 0) - Report.Error (5001, "Program " + output_file + - " does not have an entry point defined"); - return false; - } - - CodeGen.AssemblyBuilder.SetEntryPoint (ep, k); - } - - // - // Add the resources - // - if (resources != null){ - foreach (string spec in resources){ - string file, res; - int cp; - - cp = spec.IndexOf (','); - if (cp != -1){ - file = spec.Substring (0, cp); - res = spec.Substring (cp + 1); - } else - file = res = spec; - - CodeGen.AssemblyBuilder.AddResourceFile (res, file); - } - } - - if (embedded_resources != null){ - object[] margs = new object [2]; - Type[] argst = new Type [2]; - argst [0] = argst [1] = typeof (string); - MethodInfo embed_res = typeof (AssemblyBuilder).GetMethod ("EmbedResourceFile", argst); - if (embed_res == null) { - Report.Warning (0, new Location (-1), "Cannot embed resources on this runtime: try the Mono runtime instead."); - } else { - foreach (string spec in embedded_resources) { - int cp; - - cp = spec.IndexOf (','); - if (cp != -1){ - margs [0] = spec.Substring (cp + 1); - margs [1] = spec.Substring (0, cp); - } else - margs [0] = margs [1] = spec; - - if (File.Exists ((string) margs [1])) - embed_res.Invoke (CodeGen.AssemblyBuilder, margs); - else { - Report.Error (1566, "Can not find the resource " + margs [1]); - } - } - } - } - - if (Report.Errors > 0) - return false; - - CodeGen.Save (output_file); - if (timestamps) { - ShowTime ("Saved output"); - ShowTotalTime ("Total"); - } - - Timer.ShowTimers (); - - if (Report.ExpectedError != 0){ - Console.WriteLine("Failed to report expected error " + Report.ExpectedError); - Environment.Exit (1); - return false; - } -#endif -#if DEBUGME - Console.WriteLine ("Size of strings held: " + DeclSpace.length); - Console.WriteLine ("Size of strings short: " + DeclSpace.small); -#endif - //return (Report.Errors == 0); - } - - static void ManageAttributeTypes(ArrayList types) - { - Console.WriteLine("\n Attributes:"); - foreach(TypeContainer tc in types) - { - Console.WriteLine(" " + tc.Name); - } - Console.WriteLine(); - } - - public static void ManageTypeContainer(TypeContainer tc) - { - //ManageTypeContainer("", tc); - ListAllMembers(tc); - } - - public static void ListAllMembers(TypeContainer root) - { - if(root.Namespace != null) - { - Console.WriteLine("Root Namespace: " + root.Namespace.Name); - Console.WriteLine(); - } - ListTCs("", root); - } - - public static void ListEnums(string tab, ArrayList enums) - { - if(enums != null && enums.Count > 0) - { - foreach(Mono.CSharp.Enum e in enums) - { - Console.WriteLine("Enum: " + /* tab + */ e.Name); - } - } - } - - public static void ListInterfaces(string tab, ArrayList interfaces) - { - if(interfaces != null && interfaces.Count > 0) - { - foreach(Interface i in interfaces) - { - Console.WriteLine("Iface: " + /* tab + */ i.Name); - } - } - } - - public static void ListDelegates(string tab, ArrayList delegs) - { - if(delegs != null && delegs.Count > 0) - { - foreach(Delegate d in delegs) - { - Console.WriteLine("Deleg: " + /* tab + */ d.Name); - } - } - } - - public static bool IsException(TypeContainer tc) - { - Type baseType = tc.BaseType; - return (baseType == TypeManager.exception_type || - baseType.IsSubclassOf(TypeManager.exception_type)); - } - - public static bool IsAttribute(TypeContainer tc) - { - Type baseType = tc.BaseType; - return (baseType == TypeManager.attribute_type || - baseType.IsSubclassOf(TypeManager.attribute_type)); - } - - public static void ListTCs(string tab, TypeContainer tc) - { - if(tc.Types != null && tc.Types.Count > 0) - { - foreach(TypeContainer objs in tc.Types) - { - string type = "Struct: "; - if(objs is Class) - type = "Class: "; - Console.WriteLine(type + /*tab + */ objs.Name);// + " -:- " + objs.BaseType); - if(IsException(objs)) - { - Console.WriteLine("\t\t" + objs.Name + " is Exception"); - } else if(IsAttribute(objs)) - { - Console.WriteLine("\t\t" + objs.Name + " is Attribute"); - } - ListTCs(tab + "\t", objs); - } - } - ListEnums(tab, tc.Enums); - ListInterfaces(tab, tc.Interfaces); - ListDelegates(tab, tc.Delegates); - } - - public static void ManageTypeContainer(string tab, TypeContainer tc) - { - foreach(object current in tc.Types) - { - DeclSpace ds = (DeclSpace)current; - //Console.Write("\t" + ds.Namespace.Name); - //Console.WriteLine("" + ds.Documentation); - Console.WriteLine(tab + "::" + ds.Name); - if(tc.Parent != null) - { - Console.WriteLine("TypeContainer of : \"" + ds.Name + "\" = \"" + tc.Parent.Name + "\""); - } - if(ds is TypeContainer) - { - //Console.WriteLine(); - /* - if(ds is Class) - { - Class c = (Class)ds; - ArrayList b = c.Bases; - if(b != null && b.Count > 0) - { - foreach(object currentBase in b) - { - //System.Console.WriteLine("Base of {0}: {1}\tTYPE: {3}", - // ds.Name, currentBase.ToString(), - // currentBase.GetType()); - System.Console.WriteLine("Base of " + ds.Name + ": " + currentBase.ToString() - + "\tTYPE: " + currentBase.GetType()); - } - } - }*/ - ManageTypeContainer(tab + "\t", (TypeContainer)ds); - } - } - } - } -} +// +// Author: Gaurav Vaish <mas...@us...> +// +// Licensed under the terms of the GNU GPL. +// +// (C) 2003 Gaurav Vaish +// Original Authors: Miguel, Ravi, Martin +// + +namespace Mono.CSharp +{ + using System; + using System.Reflection; + using System.Reflection.Emit; + using System.Collections; + using System.IO; + using System.Text; + using System.Globalization; + using Mono.Languages; + + enum Target { + Library, Exe, Module, WinExe + }; + + /// <summary> + /// The compiler driver. + /// </summary> + public class Driver + { + + // + // Assemblies references to be linked. Initialized with + // mscorlib.dll here. + static ArrayList references; + + // + // If any of these fail, we ignore the problem. This is so + // that we can list all the assemblies in Windows and not fail + // if they are missing on Linux. + // + static ArrayList soft_references; + + // Lookup paths + static ArrayList link_paths; + + // Whether we want Yacc to output its progress + static bool yacc_verbose = false; + + static string first_source; + + //static Target target = Target.Exe; + //static string target_ext = ".exe"; + + static bool want_debugging_support = false; + + //static bool parse_only = false; + //static bool timestamps = false; + //static bool pause = false; + + // + // Whether to load the initial config file (what CSC.RSP has by default) + // + static bool load_default_config = true; + + static Hashtable response_file_list; + + // + // A list of resource files + // + static ArrayList resources; + static ArrayList embedded_resources; + + // + // An array of the defines from the command line + // + static ArrayList defines; + + // + // Output file + // + static string output_file = null; + + // + // Last time we took the time + // + static DateTime last_time, first_time; + + // + // Encoding: ISO-Latin1 is 28591 + // + static Encoding encoding; + + // + // Whether the user has specified a different encoder manually + // + static bool using_default_encoder = true; + + public static void ShowTime(string msg) + { + DateTime now = DateTime.Now; + TimeSpan span = now - last_time; + last_time = now; + + Console.WriteLine ( + "[{0:00}:{1:000}] {2}", + (int) span.TotalSeconds, span.Milliseconds, msg); + } + + public static void ShowTotalTime(string msg) + { + DateTime now = DateTime.Now; + TimeSpan span = now - first_time; + last_time = now; + + Console.WriteLine ( + "[{0:00}:{1:000}] {2}", + (int) span.TotalSeconds, span.Milliseconds, msg); + } + + // MonoTODO("Change error code for aborted compilation to something reasonable")] + static void parse(SourceFile file) + { + CSharpParser parser; + Stream input; + + try + { + input = File.OpenRead(file.Name); + } catch + { + Report.Error(2001, "Source file '" + file.Name + "' could not be opened"); + return; + } + + StreamReader reader = new StreamReader(input, encoding, using_default_encoder); + + parser = new CSharpParser (reader, file, defines); + parser.yacc_verbose = yacc_verbose; + try + { + parser.parse(); + } catch(Exception ex) + { + Report.Error(666, "Compilation aborted: " + ex); + } finally { + input.Close (); + } + } + + static void Usage() + { + // Doclet defaultDoclet = new CSDoclet(...); + // string options = defaultDoclet.UsageString(); + Console.WriteLine("" + + "C# Document Generator, (C) 2003 Gaurav Vaish\n" + + "\n" + + "usage: \n" + + "csdoc [options] [namespace-names] [sourcefiles] [@files] \n" + + " -overview <file> Read overview documentation from HTML file\n" + + " -public Show only public classes and members\n" + + " -protected Show protected/public classes and members\n" + + " -internal Show internal/protected/public classes and members\n" + + " -private Show all classes and members\n" + + " -doclet <class> Generate output via alternate doclet\n" + + //" -verbose Be verbose of what is being done\n" + + //" --reference:ASS Reference the specified assembly\n" + + " -r:ASS Same as --reference\n" + + " --help Display command line options and exit\n" + + " --about About the CSDoc Document Generator\n" + + "\n" + + "Resources:\n" + + " --linkresource FILE[,ID] Links FILE as a resource\n" + + " --resource FILE[,ID] Embed FILE as a resource\n" + + "\n" + + "Options can be of the form -option or /option" + /* options */ + ""); + } + + static void About() + { + Console.WriteLine("" + + " The CSDoc Document Generator is (C) 2003, Gaurav Vaish.\n" + + " The source code is released under the terms of the GNU GPL.\n" + + "\n" + + " For more information on CSDoc, visit the website:\n" + + " http://csdoc.sourceforge.net\n" + + "\n" + + " The application is mastermind of Gaurav Vaish.\n" + + ""); + } + + public static int Main(string[] args) + { + bool ok = MainDriver(args); + + if (ok && Report.Errors == 0) + { + Console.Write("Compilation succeeded"); + if(Report.Warnings > 0) + { + Console.Write(" - {0} warning(s)", Report.Warnings); + } + Console.WriteLine(); + return 0; + } else + { + Console.WriteLine("Compilation failed: {0} error(s), {1} warnings", + Report.Errors, Report.Warnings); + return 1; + } + } + + static public void LoadAssembly(string assembly, bool soft) + { + Assembly a; + string total_log = ""; + + try + { + char[] path_chars = { '/', '\\', '.' }; + + if (assembly.IndexOfAny(path_chars) != -1) + { + a = Assembly.LoadFrom(assembly); + } else + { + a = Assembly.Load(assembly); + } + TypeManager.AddAssembly(a); + + } catch(FileNotFoundException) + { + foreach (string dir in link_paths) + { + string full_path = Path.Combine(dir, assembly); + if(!assembly.EndsWith(".dll")) + full_path += ".dll"; + + try + { + a = Assembly.LoadFrom(full_path); + TypeManager.AddAssembly(a); + return; + } catch (FileNotFoundException ff) + { + total_log += ff.FusionLog; + continue; + } + } + if(!soft) + { + Report.Error(6, "Cannot find assembly `" + assembly + "'" ); + Console.WriteLine("Log: \n" + total_log); + } + } catch(BadImageFormatException f) + { + Report.Error(6, "Cannot load assembly (bad file format)" + f.FusionLog); + } catch(FileLoadException f) + { + Report.Error(6, "Cannot load assembly " + f.FusionLog); + } catch(ArgumentNullException) + { + Report.Error(6, "Cannot load assembly (null argument)"); + } + } + + /// <summary> + /// Loads all assemblies referenced on the command line + /// </summary> + static public void LoadReferences() + { + foreach(string r in references) + LoadAssembly(r, false); + + foreach(string r in soft_references) + LoadAssembly(r, true); + + return; + } + + static void SetupDefaultDefines() + { + defines = new ArrayList (); + defines.Add("__MonoCS__"); + defines.Add("__MCSDoc__"); + } + + static string [] LoadArgs(string file) + { + StreamReader f; + ArrayList args = new ArrayList(); + string line; + try + { + f = new StreamReader(file); + } catch + { + return null; + } + + StringBuilder sb = new StringBuilder (); + + while((line = f.ReadLine()) != null) + { + int t = line.Length; + + for (int i = 0; i < t; i++) + { + char c = line [i]; + + if (c == '"' || c == '\'') + { + char end = c; + + for(i++; i < t; i++) + { + c = line [i]; + + if (c == end) + break; + sb.Append (c); + } + } else if (c == ' ') + { + if (sb.Length > 0) + { + args.Add (sb.ToString ()); + sb.Length = 0; + } + } else + sb.Append (c); + } + if (sb.Length > 0) + { + args.Add (sb.ToString ()); + sb.Length = 0; + } + } + + string[] ret_value = new string[args.Count]; + args.CopyTo(ret_value, 0); + + return ret_value; + } + + // + // Returns the directory where the system assemblies are installed + // + static string GetSystemDir() + { + Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); + + foreach (Assembly a in assemblies) + { + string codebase = a.Location; + if(codebase.EndsWith ("corlib.dll")) + { + return codebase.Substring(0, codebase.LastIndexOf(System.IO.Path.DirectorySeparatorChar)); + } + } + + Report.Error (-15, "Can not compute my system path"); + return ""; + } + + // + // Given a path specification, splits the path from the file/pattern + // + static void SplitPathAndPattern(string spec, out string path, out string pattern) + { + int p = spec.LastIndexOf("/"); + if (p != -1){ + // + // Windows does not like /file.cs, switch that to: + // "\", "file.cs" + // + if (p == 0) + { + path = "\\"; + pattern = spec.Substring(1); + } else + { + path = spec.Substring(0, p); + pattern = spec.Substring(p + 1); + } + return; + } + + p = spec.LastIndexOf("\\"); + if (p != -1) + { + path = spec.Substring(0, p); + pattern = spec.Substring(p + 1); + return; + } + + path = "."; + pattern = spec; + } + + static void ProcessFile(string f) + { + if (first_source == null) + first_source = f; + + Location.AddFile(f); + } + + static void ProcessFiles() + { + Location.Initialize(); + + foreach(SourceFile file in Location.SourceFiles) + { + parse(file); + } + } + + static void CompileFiles(string spec, bool recurse) + { + string path, pattern; + + SplitPathAndPattern(spec, out path, out pattern); + if(pattern.IndexOf("*") == -1) + { + ProcessFile(spec); + return; + } + + string[] files = null; + try + { + files = Directory.GetFiles (path, pattern); + } catch (System.IO.DirectoryNotFoundException) + { + Report.Error (2001, "Source file `" + spec + "' could not be found"); + return; + } catch (System.IO.IOException) + { + Report.Error (2001, "Source file `" + spec + "' could not be found"); + return; + } + + foreach(string f in files) + { + ProcessFile(f); + } + + if(!recurse) + return; + + string[] dirs = null; + + try + { + dirs = Directory.GetDirectories (path); + } catch { } + + foreach(string d in dirs) + { + // Don't include path in this string, as each + // directory entry already does + CompileFiles (d + "/" + pattern, true); + } + } + + static void DefineDefaultConfig() + { + // + // For now the "default config" is harcoded into the compiler + // we can move this outside later + // + string[] default_config = + { + "System", + "System.Xml", +#if false + // + // Is it worth pre-loading all this stuff? + // + "Accessibility", + "System.Configuration.Install", + "System.Data", + "System.Design", + "System.DirectoryServices", + "System.Drawing.Design", + "System.Drawing", + "System.EnterpriseServices", + "System.Management", + "System.Messaging", + "System.Runtime.Remoting", + "System.Runtime.Serialization.Formatters.Soap", + "System.Security", + "System.ServiceProcess", + "System.Web", + "System.Web.RegularExpressions", + "System.Web.Services", + "System.Windows.Forms" +#endif + }; + + int p = 0; + foreach(string def in default_config) + soft_references.Insert(p++, def); + } + + static void SetOutputFile(string name) + { + output_file = name; + } + + static void SetWarningLevel(string s) + { + int level = 0; + + try + { + level = Int32.Parse(s); + } catch + { + Report.Error(1900, "--wlevel requires an value from 0 to 4"); + Environment.Exit(1); + } + if (level < 0 || level > 4) + { + Report.Error(1900, "Warning level must be 0 to 4"); + Environment.Exit(1); + } else + RootContext.WarningLevel = level; + } + + static void Version() + { + string version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); + Console.WriteLine("C# Document Generator Version {0}", version); + Environment.Exit(0); + } + + // + // Currently handles the Unix-like command line options, but will be + // deprecated in favor of the CSCParseOption, which will also handle the + // options that start with a dash in the future. + // + static bool UnixParseOption(string arg, ref string [] args, ref int i) + { + switch (arg) + { + + case "--version": + Version(); + return true; + + case "/?": case "/h": case "/help": + case "--help": + Usage(); + Environment.Exit(0); + return true; + + case "--about": + About(); + Environment.Exit(0); + return true; + + case "--recurse": + if ((i + 1) >= args.Length) + { + Report.Error(5, "--recurse requires an argument"); + Environment.Exit(1); + } + CompileFiles(args [++i], true); + return true; + + case "--linkresource": + case "--linkres": + if((i + 1) >= args.Length) + { + Usage(); + Report.Error(5, "Missing argument to --linkres"); + Environment.Exit(1); + } + if (resources == null) + resources = new ArrayList(); + + resources.Add(args[++i]); + return true; + + case "--resource": + case "--res": + if ((i + 1) >= args.Length) + { + Usage(); + Report.Error(5, "Missing argument to --resource"); + Environment.Exit(1); + } + if (embedded_resources == null) + embedded_resources = new ArrayList(); + + embedded_resources.Add(args[++i]); + return true; + + } + return false; + } + + // + // Currently it is very basic option parsing, but eventually, this will + // be the complete option parser + // + static bool CSCParseOption(string option, ref string [] args, ref int i) + { + int idx = option.IndexOf(":"); + string arg, value; + + if (idx == -1) + { + arg = option; + value = ""; + } else + { + arg = option.Substring (0, idx); + value = option.Substring (idx + 1); + } + + switch(arg) + { + case "/nologo": + return true; + + case "/recurse": + if (value == ""){ + Report.Error (5, "/recurse requires an argument"); + Environment.Exit (1); + } + CompileFiles (value, true); + return true; + + case "/help": + case "/?": + Usage (); + Environment.Exit (0); + return true; + + case "/linkresource": + case "/linkres": + if ((i + 1) >= args.Length) + { + Usage(); + Report.Error(5, "Missing argument to --linkres"); + Environment.Exit(1); + } + if (resources == null) + resources = new ArrayList(); + + resources.Add(args[++i]); + return true; + + case "/resource": + case "/res": + if ((i + 1) >= args.Length) + { + Usage(); + Report.Error(5, "Missing argument to --resource"); + Environment.Exit(1); + } + if (embedded_resources == null) + embedded_resources = new ArrayList(); + + embedded_resources.Add(args[++i]); + return true; + + } + return false; + } + + /// <summary> + /// Parses the arguments, and drives the compilation + /// process. + /// </summary> + /// + /// <remarks> + /// TODO: Mostly structured to debug the compiler + /// now, needs to be turned into a real driver soon. + /// </remarks> + // [MonoTODO("Change error code for unknown argument to something reasonable")] + static bool MainDriver (string [] args) + { + int i; + bool parsing_options = true; + + try + { + encoding = Encoding.GetEncoding (28591); + } catch + { + Console.WriteLine ("Error: could not load encoding 28591, trying 1252"); + encoding = Encoding.GetEncoding (1252); + } + + references = new ArrayList(); + soft_references = new ArrayList(); + link_paths = new ArrayList(); + + SetupDefaultDefines(); + + // + // Setup defaults + // + // This is not required because Assembly.Load knows about this + // path. + // + + int argc = args.Length; + for (i = 0; i < argc; i++) + { + string arg = args [i]; + + if (arg.StartsWith ("@")){ + string [] new_args, extra_args; + string response_file = arg.Substring (1); + + if (response_file_list == null) + response_file_list = new Hashtable (); + + if (response_file_list.Contains (response_file)){ + Report.Error ( + 1515, "Response file `" + response_file + + "' specified multiple times"); + Environment.Exit (1); + } + + response_file_list.Add (response_file, response_file); + + extra_args = LoadArgs (response_file); + if (extra_args == null){ + Report.Error (2011, "Unable to open response file: " + + response_file); + return false; + } + + new_args = new string [extra_args.Length + argc]; + args.CopyTo (new_args, 0); + extra_args.CopyTo (new_args, argc); + args = new_args; + argc = new_args.Length; + continue; + } + + if (parsing_options){ + if (arg == "--"){ + parsing_options = false; + continue; + } + + if (arg.StartsWith ("-")){ + if (UnixParseOption (arg, ref args, ref i)) + continue; + + // Try a -CSCOPTION + string csc_opt = "/" + arg.Substring (1); + if (CSCParseOption (csc_opt, ref args, ref i)) + continue; + } else { + if (arg.StartsWith ("/")){ + if (CSCParseOption (arg, ref args, ref i)) + continue; + } + } + } + + CompileFiles(arg, false); + } + + ProcessFiles(); + + if (first_source == null){ + Report.Error (2008, "No files to compile were specified"); + return false; + } + + if (Report.Errors > 0) + return false; + + // + // Load Core Library for default compilation + // + if (RootContext.StdLib) + references.Insert (0, "mscorlib"); + + if (load_default_config) + DefineDefaultConfig(); + + if (Report.Errors > 0) + { + return false; + } + + // + // Load assemblies required + // + first_time = last_time = DateTime.Now; + + //ShowTime("Loading references"); + + link_paths.Add(GetSystemDir()); + LoadReferences(); + + //ShowTime(" References loaded"); + + if(Report.Errors > 0) + { + return false; + } + + // + // Quick hack + // + // Unfortunately, I'll need to keep this. :-(( + output_file = "MCSDoc.dll"; + + CodeGen.Init(output_file, null, want_debugging_support); + + TypeManager.AddModule(CodeGen.ModuleBuilder); + +#if false + DateTime start = DateTime.Now; + TypeManager.GetAssemblyNamespaces (output_file); + DateTime end = DateTime.Now; + //Console.WriteLine ("Loading namespaces: " + (end - start)); + start = DateTime.Now; + //TypeManager.GetAllTypes (); + end = DateTime.Now; + //Console.WriteLine ("Getting Types: " + (end - start)); +#endif + + // + // Before emitting, we need to get the core + // types emitted from the user defined types + // or from the system ones. + // + //ShowTime("Initializing Core Types"); + + if(!RootContext.StdLib) + { + RootContext.ResolveCore(); + if(Report.Errors > 0) + return false; + } + + TypeManager.InitCoreTypes(); + + //ShowTime(" Core Types done"); + + // + // The second pass of the compiler + // + //ShowTime("Resolving tree"); + + RootContext.ResolveTree(); + + //ShowTime("Populate tree"); + + if (!RootContext.StdLib) + RootContext.BootCorlib_PopulateCoreTypes(); + RootContext.PopulateTypes(); + RootContext.DefineTypes(); + + TypeManager.InitCodeHelpers(); + + if(Report.Errors > 0) + { + System.Console.WriteLine("Exiting after initializing code helpers..."); + return false; + } + + TypeContainer root = RootContext.Tree.Types; + Console.WriteLine("Root type: " + root.GetType()); + + ManageAttributeTypes(RootContext.AttributeTypes); + + ManageTypeContainer(root); + Console.WriteLine(); + +/* + ArrayList allns = Namespace.AllNamespaces; + foreach(Namespace nsallns in allns) + { + if(nsallns.Name.Trim().Length > 0) + { + Console.WriteLine("->" + nsallns.Name); + } + } +*/ +/* + Hashtable nss = RootContext.Tree.Namespaces; + //Hashtable nss = TypeManager.GetNamespaces(); + + Console.WriteLine("Total namespaces: " + nss.Count); + foreach(object objk in nss.Keys) + { + SourceFile sf = (SourceFile) objk; + object obj = nss[objk]; + Console.WriteLine("-> " + sf.Name); + //Console.WriteLine("\t-> " + ((Namespace)nss[sf.Name]).Name); + //Console.WriteLine("->" + obj.ToString()); + //Console.WriteLine("->" + obj.GetType()); + if(obj is Hashtable) + { + Hashtable ht = (Hashtable) obj; + foreach(object objht in ht.Keys) + { + Console.WriteLine("\t->" + ((Namespace)ht[objht]).Name); + } + } + } + Console.WriteLine(); +//*/ + + return Report.Errors == 0; + // + // The code generator + // + // Now, I don't need the rest of the stuff. +#if false + if (timestamps) + ShowTime ("Emitting code"); + ShowTotalTime ("Total so far"); + RootContext.EmitCode(); + if (timestamps) + ShowTime (" done"); + + if (Report.Errors > 0){ + return false; + } + + if (timestamps) + ShowTime ("Closing types"); + + if (RootContext.WarningLevel >= 4) + if (!Namespace.VerifyUsing ()) + return false; + + RootContext.CloseTypes (); + + PEFileKinds k = PEFileKinds.ConsoleApplication; + + if (target == Target.Library || target == Target.Module) + k = PEFileKinds.Dll; + else if (target == Target.Exe) + k = PEFileKinds.ConsoleApplication; + else if (target == Target.WinExe) + k = PEFileKinds.WindowApplication; + + if (target == Target.Exe || target == Target.WinExe){ + MethodInfo ep = RootContext.EntryPoint; + + if (ep == null){ + if (Report.Errors == 0) + Report.Error (5001, "Program " + output_file + + " does not have an entry point defined"); + return false; + } + + CodeGen.AssemblyBuilder.SetEntryPoint (ep, k); + } + + // + // Add the resources + // + if (resources != null){ + foreach (string spec in resources){ + string file, res; + int cp; + + cp = spec.IndexOf (','); + if (cp != -1){ + file = spec.Substring (0, cp); + res = spec.Substring (cp + 1); + } else + file = res = spec; + + CodeGen.AssemblyBuilder.AddResourceFile (res, file); + } + } + + if (embedded_resources != null){ + object[] margs = new object [2]; + Type[] argst = new Type [2]; + argst [0] = argst [1] = typeof (string); + MethodInfo embed_res = typeof (AssemblyBuilder).GetMethod ("EmbedResourceFile", argst); + if (embed_res == null) { + Report.Warning (0, new Location (-1), "Cannot embed resources on this runtime: try the Mono runtime instead."); + } else { + foreach (string spec in embedded_resources) { + int cp; + + cp = spec.IndexOf (','); + if (cp != -1){ + margs [0] = spec.Substring (cp + 1); + margs [1] = spec.Substring (0, cp); + } else + margs [0] = margs [1] = spec; + + if (File.Exists ((string) margs [1])) + embed_res.Invoke (CodeGen.AssemblyBuilder, margs); + else { + Report.Error (1566, "Can not find the resource " + margs [1]); + } + } + } + } + + if (Report.Errors > 0) + return false; + + CodeGen.Save (output_file); + if (timestamps) { + ShowTime ("Saved output"); + ShowTotalTime ("Total"); + } + + Timer.ShowTimers (); + + if (Report.ExpectedError != 0){ + Console.WriteLine("Failed to report expected error " + Report.ExpectedError); + Environment.Exit (1); + return false; + } +#endif +#if DEBUGME + Console.WriteLine ("Size of strings held: " + DeclSpace.length); + Console.WriteLine ("Size of strings short: " + DeclSpace.small); +#endif + //return (Report.Errors == 0); + } + + static void ManageAttributeTypes(ArrayList types) + { + if(types == null || types.Count == 0) + return; + Console.WriteLine("\n Attributes:"); + foreach(TypeContainer tc in types) + { + Console.WriteLine(" " + tc.Name); + } + Console.WriteLine(); + } + + public static void ManageTypeContainer(TypeContainer tc) + { + //ManageTypeContainer("", tc); + ListAllMembers(tc); + } + + public static void ListAllMembers(TypeContainer root) + { + if(root.Namespace != null && root.Namespace.Name.Length > 0) + { + Console.WriteLine("Root Namespace: " + root.Namespace.Name); + Console.WriteLine(); + } + ListTCs("", root); + } + + public static void ListEnums(string tab, ArrayList enums) + { + if(enums != null && enums.Count > 0) + { + foreach(Mono.CSharp.Enum e in enums) + { + if(e.Documentation.Length > 0) + { + Console.WriteLine("Enum: " + /* tab + */ e.Name); + Console.WriteLine("Documentation: \n" + e.Documentation); + Console.WriteLine(); + } + } + } + } + + public static void ListInterfaces(string tab, ArrayList interfaces) + { + if(interfaces != null && interfaces.Count > 0) + { + foreach(Interface i in interfaces) + { + if(i.Documentation.Length > 0) + { + Console.WriteLine("Iface: " + /* tab + */ i.Name); + Console.WriteLine("Documentation: \n" + i.Documentation); + Console.WriteLine(); + } + } + } + } + + public static void ListDelegates(string tab, ArrayList delegs) + { + if(delegs != null && delegs.Count > 0) + { + foreach(Delegate d in delegs) + { + if(d.Documentation.Length > 0) + { + Console.WriteLine("Deleg: " + /* tab + */ d.Name); + Console.WriteLine("Documentation: \n" + d.Documentation); + Console.WriteLine(); + } + } + } + } + + public static bool IsException(TypeContainer tc) + { + Type baseType = tc.BaseType; + return (baseType == TypeManager.exception_type || + baseType.IsSubclassOf(TypeManager.exception_type)); + } + + public static bool IsAttribute(TypeContainer tc) + { + Type baseType = tc.BaseType; + return (baseType == TypeManager.attribute_type || + baseType.IsSubclassOf(TypeManager.attribute_type)); + } + + public static void ListTCs(string tab, TypeContainer tc) + { + if(tc.Types != null && tc.Types.Count > 0) + { + foreach(TypeContainer objs in tc.Types) + { + if(objs.Documentation.Trim().Length > 0) + { + string type = "Struct: "; + if(objs is Class) + type = "Class: "; + Console.WriteLine(type + /*tab + */ objs.Name);// + " -:- " + objs.BaseType); + if(IsException(objs)) + { + Console.WriteLine("\t\t" + objs.Name + " is Exception"); + } else if(IsAttribute(objs)) + { + Console.WriteLine("\t\t" + objs.Name + " is Attribute"); + } + Console.WriteLine("D... [truncated message content] |
From: Gaurav V. <mas...@us...> - 2003-04-08 06:24:45
|
Update of /cvsroot/csdoc/csdoc/src/csdoc In directory sc8-pr-cvs1:/tmp/cvs-serv16374 Modified Files: driver.cs namespace.cs ChangeLog Log Message: 2003-04-08 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * driver.cs : Easier way to get exception / attribute. * namespace.cs : AllNamespaces { get; } - Added property. Index: driver.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/driver.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- driver.cs 8 Apr 2003 06:16:22 -0000 1.9 +++ driver.cs 8 Apr 2003 06:24:42 -0000 1.10 @@ -875,9 +875,45 @@ TypeContainer root = RootContext.Tree.Types; Console.WriteLine("Root type: " + root.GetType()); + ManageAttributeTypes(RootContext.AttributeTypes); + ManageTypeContainer(root); + Console.WriteLine(); +/* + ArrayList allns = Namespace.AllNamespaces; + foreach(Namespace nsallns in allns) + { + if(nsallns.Name.Trim().Length > 0) + { + Console.WriteLine("->" + nsallns.Name); + } + } +*/ +/* + Hashtable nss = RootContext.Tree.Namespaces; + //Hashtable nss = TypeManager.GetNamespaces(); + + Console.WriteLine("Total namespaces: " + nss.Count); + foreach(object objk in nss.Keys) + { + SourceFile sf = (SourceFile) objk; + object obj = nss[objk]; + Console.WriteLine("-> " + sf.Name); + //Console.WriteLine("\t-> " + ((Namespace)nss[sf.Name]).Name); + //Console.WriteLine("->" + obj.ToString()); + //Console.WriteLine("->" + obj.GetType()); + if(obj is Hashtable) + { + Hashtable ht = (Hashtable) obj; + foreach(object objht in ht.Keys) + { + Console.WriteLine("\t->" + ((Namespace)ht[objht]).Name); + } + } + } Console.WriteLine(); +//*/ return Report.Errors == 0; // @@ -997,6 +1033,16 @@ //return (Report.Errors == 0); } + static void ManageAttributeTypes(ArrayList types) + { + Console.WriteLine("\n Attributes:"); + foreach(TypeContainer tc in types) + { + Console.WriteLine(" " + tc.Name); + } + Console.WriteLine(); + } + public static void ManageTypeContainer(TypeContainer tc) { //ManageTypeContainer("", tc); @@ -1049,31 +1095,15 @@ public static bool IsException(TypeContainer tc) { Type baseType = tc.BaseType; - while(baseType != null) - { - //Console.WriteLine("Base: " + baseType.ToString()); - if(baseType.IsSubclassOf(TypeManager.exception_type)) - { - return true; - } - baseType = baseType.BaseType; - } - return false; + return (baseType == TypeManager.exception_type || + baseType.IsSubclassOf(TypeManager.exception_type)); } public static bool IsAttribute(TypeContainer tc) { Type baseType = tc.BaseType; - while(baseType != null) - { - //Console.WriteLine("Base: " + baseType.ToString()); - if(baseType.IsSubclassOf(TypeManager.attribute_type)) - { - return true; - } - baseType = baseType.BaseType; - } - return false; + return (baseType == TypeManager.attribute_type || + baseType.IsSubclassOf(TypeManager.attribute_type)); } public static void ListTCs(string tab, TypeContainer tc) @@ -1085,8 +1115,7 @@ string type = "Struct: "; if(objs is Class) type = "Class: "; - Console.WriteLine(type + /*tab + */ objs.Name); - //Console.WriteLine("\t\t" + objs.BaseType.BaseType); + Console.WriteLine(type + /*tab + */ objs.Name);// + " -:- " + objs.BaseType); if(IsException(objs)) { Console.WriteLine("\t\t" + objs.Name + " is Exception"); Index: namespace.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/namespace.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- namespace.cs 19 Feb 2003 05:50:12 -0000 1.1 +++ namespace.cs 8 Apr 2003 06:24:42 -0000 1.2 @@ -45,7 +45,21 @@ Used = false; } } - + + /// <summary> + /// Returns the list of all the added namespaces. + /// </summary> + /// <remarks> + /// Master's Quick Hack + /// </remarks> + public static ArrayList AllNamespaces + { + get + { + return all_namespaces; + } + } + /// <summary> /// Constructor Takes the current namespace and the /// name. This is bootstrapped with parent == null Index: ChangeLog =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/ChangeLog,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- ChangeLog 8 Apr 2003 06:16:22 -0000 1.21 +++ ChangeLog 8 Apr 2003 06:24:42 -0000 1.22 @@ -1,4 +1,9 @@ +2003-04-08 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + + * driver.cs : Easier way to get exception / attribute. + * namespace.cs : AllNamespaces { get; } - Added property. + 2003-04-07 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * codegen.cs : No need for file name while |
From: Gaurav V. <mas...@us...> - 2003-04-08 06:22:13
|
Update of /cvsroot/csdoc/csdoc/src/tests In directory sc8-pr-cvs1:/tmp/cvs-serv14311 Modified Files: ChangeLog test_05.cs test_19.cs validTests Added Files: test_22.cs test_23.cs test_24.cs Log Message: 2003-04-07 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * test_24.cs : More than one namespace. 2003-04-06 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * test_05.cs, * test_22.cs : Class name clarifies that it's an exception. * test_22.cs, * test_23.cs : Added new tests - Exception, Attribute. --- NEW FILE --- using System; public class test_22Exception : test_05Exception { // Default ctor public test_22Exception() : base() { } // ctor with message public test_22Exception(string message) : base(message) { } } --- NEW FILE --- using System; /** * <summary>Hello</summary> */ [AttributeUsage(AttributeTargets.All)] public class test_23Attribute : test_19Attribute { private int otherValue; public test_23Attribute() { } public int OtherValue { get { return otherValue; } set { this.otherValue = value; } } } --- NEW FILE --- using System; /** * <summary>CSDoc.Test/summary> */ namespace MCSDoc.Tests { namespace TestInner { enum test_24 { One, Two } } public struct test_24 { public int Zero { get { return 0; } } } } namespace MCSDoc.Tests1 { enum test_24 { One, Two } } Index: ChangeLog =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/tests/ChangeLog,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- ChangeLog 28 Mar 2003 12:07:49 -0000 1.16 +++ ChangeLog 8 Apr 2003 06:22:09 -0000 1.17 @@ -1,4 +1,15 @@ +2003-04-07 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + + * test_24.cs : More than one namespace. + +2003-04-06 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + + * test_05.cs, + * test_22.cs : Class name clarifies that it's an exception. + * test_22.cs, + * test_23.cs : Added new tests - Exception, Attribute. + 2003-03-28 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * test_21.cs : Attributes. Nothing extra as such. Index: test_05.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/tests/test_05.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- test_05.cs 20 Feb 2003 13:52:18 -0000 1.1 +++ test_05.cs 8 Apr 2003 06:22:10 -0000 1.2 @@ -1,14 +1,14 @@ using System; -public class test_05 : Exception +public class test_05Exception : Exception { // Default ctor - public test_05() : base() + public test_05Exception() : base() { } // ctor with message - public test_05(string message) : base(message) + public test_05Exception(string message) : base(message) { } } Index: test_19.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/tests/test_19.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- test_19.cs 26 Mar 2003 14:50:43 -0000 1.1 +++ test_19.cs 8 Apr 2003 06:22:10 -0000 1.2 @@ -4,11 +4,11 @@ * <summary>Hello</summary> */ [AttributeUsage(AttributeTargets.All)] -public class test_19 : Attribute +public class test_19Attribute : Attribute { private int value; - public test_19() + public test_19Attribute() { } Index: validTests =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/tests/validTests,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- validTests 28 Mar 2003 12:07:50 -0000 1.7 +++ validTests 8 Apr 2003 06:22:10 -0000 1.8 @@ -15,4 +15,7 @@ test_18.cs test_19.cs test_20.cs -test_21.cs \ No newline at end of file +test_21.cs +test_22.cs +test_23.cs +test_24.cs \ No newline at end of file |
From: Gaurav V. <mas...@us...> - 2003-04-08 06:17:51
|
Update of /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc In directory sc8-pr-cvs1:/tmp/cvs-serv11320 Modified Files: ChangeLog ClassDoc.cs Log Message: 2003-04-06 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * ClassDoc.cs : Checking for exception and attribute. Ummm! Looks clumsy. Will rectify it later. Index: ChangeLog =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/ChangeLog,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- ChangeLog 2 Apr 2003 10:22:20 -0000 1.14 +++ ChangeLog 8 Apr 2003 06:17:47 -0000 1.15 @@ -1,4 +1,9 @@ +2003-04-06 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + + * ClassDoc.cs : Checking for exception and attribute. + Ummm! Looks clumsy. Will rectify it later. + 2003-04-02 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * DocTreeGenerator.cs : ParseAndGenerate() - No need for Index: ClassDoc.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/ClassDoc.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ClassDoc.cs 2 Apr 2003 10:22:20 -0000 1.5 +++ ClassDoc.cs 8 Apr 2003 06:17:48 -0000 1.6 @@ -42,9 +42,22 @@ */ if(klass.BaseType != null) { - isAttribute = (klass.BaseType.ToString() == "System.Attribute"); - isException = (klass.BaseType.ToString() == "System.Exception"); + isAttribute = IsSubtypeOf(TypeManager.attribute_type); + isException = IsSubtypeOf(TypeManager.exception_type); } + } + + private bool IsSubtypeOf(Type type) + { + Type baseType = klass.BaseType; + while(baseType != null && + baseType.ToString() != type.ToString()) + { + if(baseType.IsSubclassOf(type)) + return true; + baseType = baseType.BaseType; + } + return false; } protected Class Class |
From: Gaurav V. <mas...@us...> - 2003-04-08 06:16:28
|
Update of /cvsroot/csdoc/csdoc/src/csdoc In directory sc8-pr-cvs1:/tmp/cvs-serv10407 Modified Files: codegen.cs driver.cs ChangeLog Log Message: 2003-04-07 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * codegen.cs : No need for file name while creating dynamic assembly and module. * driver.cs : Playing with various members. Trying to figure out how to find is a class is an attribute or an exception. Index: codegen.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/codegen.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- codegen.cs 19 Feb 2003 05:50:12 -0000 1.1 +++ codegen.cs 8 Apr 2003 06:16:22 -0000 1.2 @@ -92,7 +92,7 @@ current_domain = AppDomain.CurrentDomain; AssemblyBuilder = current_domain.DefineDynamicAssembly ( - an, AssemblyBuilderAccess.RunAndSave, Dirname (name)); + an, AssemblyBuilderAccess.RunAndSave/*, Dirname (name)*/); // // Pass a path-less name to DefineDynamicModule. Wonder how @@ -103,7 +103,7 @@ // load the default symbol writer. // ModuleBuilder = AssemblyBuilder.DefineDynamicModule ( - Basename (name), Basename (output), want_debugging_support); + Basename (name), /*Basename (output),*/ want_debugging_support); if (want_debugging_support) InitializeSymbolWriter (); Index: driver.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/driver.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- driver.cs 25 Feb 2003 12:26:35 -0000 1.8 +++ driver.cs 8 Apr 2003 06:16:22 -0000 1.9 @@ -787,9 +787,10 @@ references.Insert (0, "mscorlib"); if (load_default_config) - DefineDefaultConfig (); + DefineDefaultConfig(); - if (Report.Errors > 0){ + if (Report.Errors > 0) + { return false; } @@ -798,14 +799,15 @@ // first_time = last_time = DateTime.Now; - ShowTime ("Loading references"); + //ShowTime("Loading references"); link_paths.Add(GetSystemDir()); LoadReferences(); - ShowTime(" References loaded"); + //ShowTime(" References loaded"); - if (Report.Errors > 0){ + if(Report.Errors > 0) + { return false; } @@ -814,9 +816,8 @@ // // Unfortunately, I'll need to keep this. :-(( output_file = "MCSDoc.dll"; - //*/ - CodeGen.Init(output_file, output_file, want_debugging_support); + CodeGen.Init(output_file, null, want_debugging_support); TypeManager.AddModule(CodeGen.ModuleBuilder); @@ -836,9 +837,9 @@ // types emitted from the user defined types // or from the system ones. // - ShowTime("Initializing Core Types"); + //ShowTime("Initializing Core Types"); - if (!RootContext.StdLib) + if(!RootContext.StdLib) { RootContext.ResolveCore(); if(Report.Errors > 0) @@ -847,30 +848,38 @@ TypeManager.InitCoreTypes(); - ShowTime(" Core Types done"); + //ShowTime(" Core Types done"); // // The second pass of the compiler // - ShowTime("Resolving tree"); + //ShowTime("Resolving tree"); RootContext.ResolveTree(); - ShowTime("Populate tree"); + //ShowTime("Populate tree"); if (!RootContext.StdLib) - RootContext.BootCorlib_PopulateCoreTypes (); + RootContext.BootCorlib_PopulateCoreTypes(); RootContext.PopulateTypes(); RootContext.DefineTypes(); - TypeManager.InitCodeHelpers (); + TypeManager.InitCodeHelpers(); - if (Report.Errors > 0) + if(Report.Errors > 0) { System.Console.WriteLine("Exiting after initializing code helpers..."); return false; } + TypeContainer root = RootContext.Tree.Types; + Console.WriteLine("Root type: " + root.GetType()); + + ManageTypeContainer(root); + + Console.WriteLine(); + + return Report.Errors == 0; // // The code generator // @@ -985,8 +994,149 @@ Console.WriteLine ("Size of strings held: " + DeclSpace.length); Console.WriteLine ("Size of strings short: " + DeclSpace.small); #endif - return (Report.Errors == 0); + //return (Report.Errors == 0); } + public static void ManageTypeContainer(TypeContainer tc) + { + //ManageTypeContainer("", tc); + ListAllMembers(tc); + } + + public static void ListAllMembers(TypeContainer root) + { + if(root.Namespace != null) + { + Console.WriteLine("Root Namespace: " + root.Namespace.Name); + Console.WriteLine(); + } + ListTCs("", root); + } + + public static void ListEnums(string tab, ArrayList enums) + { + if(enums != null && enums.Count > 0) + { + foreach(Mono.CSharp.Enum e in enums) + { + Console.WriteLine("Enum: " + /* tab + */ e.Name); + } + } + } + + public static void ListInterfaces(string tab, ArrayList interfaces) + { + if(interfaces != null && interfaces.Count > 0) + { + foreach(Interface i in interfaces) + { + Console.WriteLine("Iface: " + /* tab + */ i.Name); + } + } + } + + public static void ListDelegates(string tab, ArrayList delegs) + { + if(delegs != null && delegs.Count > 0) + { + foreach(Delegate d in delegs) + { + Console.WriteLine("Deleg: " + /* tab + */ d.Name); + } + } + } + + public static bool IsException(TypeContainer tc) + { + Type baseType = tc.BaseType; + while(baseType != null) + { + //Console.WriteLine("Base: " + baseType.ToString()); + if(baseType.IsSubclassOf(TypeManager.exception_type)) + { + return true; + } + baseType = baseType.BaseType; + } + return false; + } + + public static bool IsAttribute(TypeContainer tc) + { + Type baseType = tc.BaseType; + while(baseType != null) + { + //Console.WriteLine("Base: " + baseType.ToString()); + if(baseType.IsSubclassOf(TypeManager.attribute_type)) + { + return true; + } + baseType = baseType.BaseType; + } + return false; + } + + public static void ListTCs(string tab, TypeContainer tc) + { + if(tc.Types != null && tc.Types.Count > 0) + { + foreach(TypeContainer objs in tc.Types) + { + string type = "Struct: "; + if(objs is Class) + type = "Class: "; + Console.WriteLine(type + /*tab + */ objs.Name); + //Console.WriteLine("\t\t" + objs.BaseType.BaseType); + if(IsException(objs)) + { + Console.WriteLine("\t\t" + objs.Name + " is Exception"); + } else if(IsAttribute(objs)) + { + Console.WriteLine("\t\t" + objs.Name + " is Attribute"); + } + ListTCs(tab + "\t", objs); + } + } + ListEnums(tab, tc.Enums); + ListInterfaces(tab, tc.Interfaces); + ListDelegates(tab, tc.Delegates); + } + + public static void ManageTypeContainer(string tab, TypeContainer tc) + { + foreach(object current in tc.Types) + { + DeclSpace ds = (DeclSpace)current; + //Console.Write("\t" + ds.Namespace.Name); + //Console.WriteLine("" + ds.Documentation); + Console.WriteLine(tab + "::" + ds.Name); + if(tc.Parent != null) + { + Console.WriteLine("TypeContainer of : \"" + ds.Name + "\" = \"" + tc.Parent.Name + "\""); + } + if(ds is TypeContainer) + { + //Console.WriteLine(); + /* + if(ds is Class) + { + Class c = (Class)ds; + ArrayList b = c.Bases; + if(b != null && b.Count > 0) + { + foreach(object currentBase in b) + { + //System.Console.WriteLine("Base of {0}: {1}\tTYPE: {3}", + // ds.Name, currentBase.ToString(), + // currentBase.GetType()); + System.Console.WriteLine("Base of " + ds.Name + ": " + currentBase.ToString() + + "\tTYPE: " + currentBase.GetType()); + } + } + }*/ + ManageTypeContainer(tab + "\t", (TypeContainer)ds); + } + } + } } } Index: ChangeLog =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/ChangeLog,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- ChangeLog 28 Mar 2003 18:10:42 -0000 1.20 +++ ChangeLog 8 Apr 2003 06:16:22 -0000 1.21 @@ -1,4 +1,12 @@ +2003-04-07 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + + * codegen.cs : No need for file name while + creating dynamic assembly and module. + * driver.cs : Playing with various members. + Trying to figure out how to find is + a class is an attribute or an exception. + 2003-03-28 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * cs-parser.jay : Attributes cannot be applied |
From: Gaurav V. <mas...@us...> - 2003-04-02 10:22:24
|
Update of /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc In directory sc8-pr-cvs1:/tmp/cvs-serv16460 Modified Files: ChangeLog ClassDoc.cs DocTreeGenerator.cs NamespaceDoc.cs RootDoc.cs Log Message: 2003-04-02 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * DocTreeGenerator.cs : ParseAndGenerate() - No need for multiple calls here itself. : GenerateTree() - Lot of work. * NamespaceDoc.cs : No need for subnamespaces. * ClassDoc.cs : Implements IComparable. Need while sorting the array. Index: ChangeLog =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/ChangeLog,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- ChangeLog 1 Apr 2003 16:53:47 -0000 1.13 +++ ChangeLog 2 Apr 2003 10:22:20 -0000 1.14 @@ -1,4 +1,13 @@ +2003-04-02 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + + * DocTreeGenerator.cs : ParseAndGenerate() - No need for + multiple calls here itself. + : GenerateTree() - Lot of work. + * NamespaceDoc.cs : No need for subnamespaces. + * ClassDoc.cs : Implements IComparable. Need while + sorting the array. + 2003-04-01 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * NamespaceDoc.cs : Name { get; } - Added, Index: ClassDoc.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/ClassDoc.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ClassDoc.cs 28 Mar 2003 15:30:22 -0000 1.4 +++ ClassDoc.cs 2 Apr 2003 10:22:20 -0000 1.5 @@ -13,7 +13,7 @@ namespace MCSDoc { - internal class ClassDoc : IClassDoc + internal class ClassDoc : IClassDoc, IComparable { private Class klass; private string name; @@ -55,6 +55,14 @@ } } + public string NamespaceName + { + get + { + throw new NotImplementedException(); + } + } + public string Name { get @@ -109,6 +117,23 @@ { return this.container; } + } + + public int CompareTo(object obj) + { + if(obj is ClassDoc) + { + ClassDoc other = (ClassDoc) obj; + string otherName = other.Name; + if(other.NamespaceName == this.NamespaceName) + { + return (this.Name.CompareTo(other.Name)); + } + // I know this is wrong. + return NamespaceName.CompareTo(other.NamespaceName); + } + throw new ArgumentException("[CompareTo] obj is not of" + + " type ClassDoc"); } } } Index: DocTreeGenerator.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/DocTreeGenerator.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- DocTreeGenerator.cs 1 Apr 2003 16:36:47 -0000 1.6 +++ DocTreeGenerator.cs 2 Apr 2003 10:22:20 -0000 1.7 @@ -40,10 +40,11 @@ private void ParseAndGenerate() { //rootDoc.Parse(root); - ParseContainers(root.Types); - ParseDelegates(root.Delegates); - ParseEnums(root.Enums); - ParseInterfaces(root.Interfaces); + //ParseContainers(root.Types); + //ParseDelegates(root.Delegates); + //ParseEnums(root.Enums); + //ParseInterfaces(root.Interfaces); + ParseCotnainer(root); //First need to populate [allNamespaces] //or should I populate while generating tree? @@ -51,6 +52,18 @@ GenerateTree(); } + private void GenerateTree() + { + rootDoc = new RootDoc(); + //Need to add ONLY namespaces and all types + //that are not inside any namespace. + //Namespaces will recursively contain all the + //types that are within any namespace. + //Now, I will go home today and work on the + //exact logic for whole of this system! + throw new NotImplementedException(); + } + private void ParseNamespaces() { foreach(ClassDoc cd in this.allClasses) @@ -210,11 +223,6 @@ allInterfaces.Add(id); } } - } - - private void GenerateTree() - { - throw new NotImplementedException(); } public IRootDoc RootDoc Index: NamespaceDoc.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/NamespaceDoc.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- NamespaceDoc.cs 1 Apr 2003 16:53:47 -0000 1.3 +++ NamespaceDoc.cs 2 Apr 2003 10:22:20 -0000 1.4 @@ -37,6 +37,10 @@ /// <summary> /// Will create a hierarchy of NamespaceDoc elements. /// </summary> + /// <remarks> + /// btw, do I really need this scrap funda of Parent namespace + /// and sub-namespaces? + /// </remarks> public static ArrayList CreateHierarchy(ArrayList namespaceDocs) { ArrayList retVal = new ArrayList(); @@ -47,9 +51,8 @@ foreach(NamespaceDoc nd in namespaces) { name = nd.Name; - // is this namespace is not added, - // check for its parent ones bool isAdded = IsNamespaceAdded(name, retVal); + /* if(!isAdded) { subNames = GetSubnames(name); @@ -64,13 +67,19 @@ } } } + */ + AddNamespaceInHierarchy(nd, retVal); throw new NotImplementedException(); - //if(!isAdded) - // AddNamespaceInHierarchy(name, } throw new NotImplementedException(); } + } + + private static void AddNamespaceInHierarchy(NamespaceDoc doc, + ArrayList docList) + { + throw new NotImplementedException(); } private static bool IsNamespaceAdded(string name, ArrayList namespaces) Index: RootDoc.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/RootDoc.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- RootDoc.cs 1 Apr 2003 16:04:09 -0000 1.7 +++ RootDoc.cs 2 Apr 2003 10:22:20 -0000 1.8 @@ -29,6 +29,11 @@ //Parse(root); } + public RootDoc() + { + //Do nothing! + } + private void Parse(TypeContainer root) { PopulateContainers(root.Types); |
From: Gaurav V. <mas...@us...> - 2003-04-01 16:53:51
|
Update of /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc In directory sc8-pr-cvs1:/tmp/cvs-serv13525 Modified Files: ChangeLog NamespaceDoc.cs Log Message: 2003-04-01 * NamespaceDoc.cs : Name { get; } - Added, CreateHierarchy(ArrayList) - Init impl, IsNamespaceAdded(string, ArrayList), IsNamespaceAdded(string, NamespaceDoc), GetSubnames(string) - Added. Index: ChangeLog =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/ChangeLog,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- ChangeLog 1 Apr 2003 16:36:47 -0000 1.12 +++ ChangeLog 1 Apr 2003 16:53:47 -0000 1.13 @@ -1,6 +1,14 @@ 2003-04-01 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + * NamespaceDoc.cs : Name { get; } - Added, + CreateHierarchy(ArrayList) - Init impl, + IsNamespaceAdded(string, ArrayList), + IsNamespaceAdded(string, NamespaceDoc), + GetSubnames(string) - Added. + +2003-04-01 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + * INamespaceDoc.cs : Namespaces { get; } - Sub-namespaces. * DocTreeGenerator.cs : Parsing done. Generation to start. * NamespaceDoc.cs : CreateHierarchy(ArrayList) - Stubbed. Index: NamespaceDoc.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/NamespaceDoc.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- NamespaceDoc.cs 1 Apr 2003 16:36:48 -0000 1.2 +++ NamespaceDoc.cs 1 Apr 2003 16:53:47 -0000 1.3 @@ -40,12 +40,84 @@ public static ArrayList CreateHierarchy(ArrayList namespaceDocs) { ArrayList retVal = new ArrayList(); + string name; + string[] subNames; if(namespaceDocs != null && namespaceDocs.Count > 0) { + foreach(NamespaceDoc nd in namespaces) + { + name = nd.Name; + // is this namespace is not added, + // check for its parent ones + bool isAdded = IsNamespaceAdded(name, retVal); + if(!isAdded) + { + subNames = GetSubnames(name); + if(subNames != null) + { + foreach(string subName in subNames) + { + isAdded &= IsNamespaceAdded(subName, + retVal); + if(isAdded) + break; + } + } + } + throw new NotImplementedException(); + //if(!isAdded) + // AddNamespaceInHierarchy(name, + + } throw new NotImplementedException(); } } + private static bool IsNamespaceAdded(string name, ArrayList namespaces) + { + foreach(NamespaceDoc nsd in namespaces) + { + if(IsNamespaceAdded(name, nsd) + return true; + } + return false; + } + + private static bool IsNamespaceAdded(string name, NamespaceDoc doc) + { + throw new NotImplementedException(); + } + + private static string[] GetSubnames(string name) + { + int dotCount = 0; + foreach(char c in name) + { + if(c == '.') + dotCount++; + } + + if(dotCount == 0) + return null; + + int[] dotIndices = new int[dotCount]; + int cIndex = 0; + int cPos = 0; + + for(cPos = 0; cPos < name.Length; cPos++) + { + if(name[cPos] == '.') + dotIndices[cIndex++] = cPos; + } + + string retVal[] = new string[dotCount]; + for(cIndex = 0; cIndex < dotCount; cIndex++) + { + retVal[cIndex] = name.Substring(0, dotIndices[cIndex] - 1); + } + return retVal; + } + public void AddClassDoc(IClassDoc doc) { classes.Add(doc); @@ -69,6 +141,14 @@ public void AddInterfaceDoc(IInterfaceDoc doc) { interfaces.Add(doc); + } + + public string Name + { + get + { + return this.name; + } } public string Comments |
From: Gaurav V. <mas...@us...> - 2003-04-01 16:36:52
|
Update of /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc In directory sc8-pr-cvs1:/tmp/cvs-serv5935 Modified Files: ChangeLog DocTreeGenerator.cs INamespaceDoc.cs NamespaceDoc.cs Log Message: 2003-04-01 * INamespaceDoc.cs : Namespaces { get; } - Sub-namespaces. * DocTreeGenerator.cs : Parsing done. Generation to start. * NamespaceDoc.cs : CreateHierarchy(ArrayList) - Stubbed. Index: ChangeLog =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/ChangeLog,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- ChangeLog 1 Apr 2003 16:04:09 -0000 1.11 +++ ChangeLog 1 Apr 2003 16:36:47 -0000 1.12 @@ -1,6 +1,12 @@ 2003-04-01 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + * INamespaceDoc.cs : Namespaces { get; } - Sub-namespaces. + * DocTreeGenerator.cs : Parsing done. Generation to start. + * NamespaceDoc.cs : CreateHierarchy(ArrayList) - Stubbed. + +2003-04-01 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + * AttributeDoc.cs : Oops! Forgot to add last time. * RootDoc.cs : Don't parse here. * DocTreeGenerator.cs : Making it come to use. Index: DocTreeGenerator.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/DocTreeGenerator.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- DocTreeGenerator.cs 1 Apr 2003 16:04:09 -0000 1.5 +++ DocTreeGenerator.cs 1 Apr 2003 16:36:47 -0000 1.6 @@ -15,15 +15,15 @@ { internal class DocTreeGenerator { - private TypeContainer root; - private RootDoc rootDoc; + private TypeContainer root = null; + private RootDoc rootDoc = null; - private ArrayList allNamespaces; - private ArrayList allClasses; - private ArrayList allStructs; - private ArrayList allDelegates; - private ArrayList allEnums; - private ArrayList allInterfaces; + private ArrayList allNamespaces = new ArrayList(); + private ArrayList allClasses = new ArrayList(); + private ArrayList allStructs = new ArrayList(); + private ArrayList allDelegates = new ArrayList(); + private ArrayList allEnums = new ArrayList(); + private ArrayList allInterfaces = new ArrayList(); public DocTreeGenerator(TypeContainer root) { @@ -44,8 +44,93 @@ ParseDelegates(root.Delegates); ParseEnums(root.Enums); ParseInterfaces(root.Interfaces); + //First need to populate [allNamespaces] - //GenerateTree(); + //or should I populate while generating tree? + ParseNamespaces(); + GenerateTree(); + } + + private void ParseNamespaces() + { + foreach(ClassDoc cd in this.allClasses) + { + if(cd.Namespace.Name != null) + { + OptNamespaceAdd(cd.Namespace.Name); + } + } + + foreach(StructDoc sd in this.allStructs) + { + if(sd.Namespace.Name != null) + { + OptNamespaceAdd(sd.Namespace.Name); + } + } + + foreach(EnumDoc ed in this.allEnums) + { + if(ed.Namespace.Name != null) + { + OptNamespaceAdd(ed.Namespace.Name); + } + } + + foreach(InterfaceDoc id in this.allInterfaces) + { + if(id.Namespace.Name != null) + { + OptNamespaceAdd(id.Namespace.Name); + } + } + + foreach(DelegateDoc dd in this.allDelegates) + { + if(dd.Namespace.Name != null) + { + OptNamespaceAdd(dd.Namespace.Name); + } + } + } + + private void OptNamespaceAdd(string name) + { + foreach(NamespaceDoc current in allNamespaces) + { + if(current.Name == name) + { + return; + } + } + + NamespaceDoc nsd = new NamespaceDoc(name); + allNamespaces.Add(nsd); + } + + private void HandleNamespaceClass(Class klass, ClassDoc doc) + { + NamespaceDoc nsd = NamespaceLookup(klass.Namespace.Name); + nsd.AddClassDoc(doc); + } + + private void HandleNamespaceStruct(Struct esstruct, StructDoc doc) + { + NamespaceDoc nsd = NamespaceLookup(esstruct.Namespace.Name); + nsd.AddStructDoc(doc); + } + + private void HandleNamespaceEnum(Mono.CSharp.Enum eenum, + Mono.CSharp.Enum doc) + { + NamespaceDoc nsd = NamespaceLookup(eenum.Namespace.Name); + allNamespaces.AddClassDoc(doc); + } + + private void HandleNamespaceStruct(Struct esstruct, StructDoc doc) + { + NamespaceDoc nsd = NamespaceLookup(esstruct.Namespace.Name); + nsd.AddStructDoc(doc); } private void ParseContainers(ArrayList containers) @@ -95,7 +180,7 @@ { if(delegates != null && delegates.Count > 0) { - foreach(Delegate deleg in delegates) + foreach(Mono.CSharp.Delegate deleg in delegates) { DelegateDoc dd = new DelegateDoc(deleg); allDelegates.Add(dd); Index: INamespaceDoc.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/INamespaceDoc.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- INamespaceDoc.cs 28 Mar 2003 14:23:56 -0000 1.3 +++ INamespaceDoc.cs 1 Apr 2003 16:36:48 -0000 1.4 @@ -16,6 +16,8 @@ string Comments { get; } string Name { get; } + INamespaceDoc[] Namespaces { get; } + IClassDoc[] Classes { get; } IDelegateDoc[] Delegates { get; } IEnumDoc[] Enums { get; } Index: NamespaceDoc.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/NamespaceDoc.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- NamespaceDoc.cs 28 Mar 2003 14:23:57 -0000 1.1 +++ NamespaceDoc.cs 1 Apr 2003 16:36:48 -0000 1.2 @@ -34,11 +34,23 @@ throw new NotImplementedException(); } + /// <summary> + /// Will create a hierarchy of NamespaceDoc elements. + /// </summary> + public static ArrayList CreateHierarchy(ArrayList namespaceDocs) + { + ArrayList retVal = new ArrayList(); + if(namespaceDocs != null && namespaceDocs.Count > 0) + { + throw new NotImplementedException(); + } + } + public void AddClassDoc(IClassDoc doc) { classes.Add(doc); } - + public void AddStructDoc(IStructDoc doc) { structs.Add(doc); |
From: Gaurav V. <mas...@us...> - 2003-04-01 16:04:19
|
Update of /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc In directory sc8-pr-cvs1:/tmp/cvs-serv22343 Modified Files: ChangeLog DocTreeGenerator.cs RootDoc.cs Added Files: AttributeDoc.cs Log Message: 2003-04-01 * AttributeDoc.cs : Oops! Forgot to add last time. * RootDoc.cs : Don't parse here. * DocTreeGenerator.cs : Making it come to use. --- NEW FILE --- /** * Project: Master C# Document Generator * Contact: mas...@us... * Web: http://csdoc.sourceforge.net * * Copyright: (C) 2003, Gaurav Vaish * */ using Mono.CSharp; using System; namespace MCSDoc { internal class AttributeDoc : ClassDoc, IAttributeDoc { private AccessFlags flags; private AttributeTargets targets; public AttributeDoc(Class klass) : base(klass) { if(!base.IsAttribute) throw new Exception("[AttributeDoc] Class is not an attribute"); } public AccessFlags Flags { get { throw new NotImplementedException() } } public AttributeTargets Targets { get { throw new NotImplementedException() } } } } Index: ChangeLog =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/ChangeLog,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- ChangeLog 28 Mar 2003 15:30:17 -0000 1.10 +++ ChangeLog 1 Apr 2003 16:04:09 -0000 1.11 @@ -1,4 +1,10 @@ +2003-04-01 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + + * AttributeDoc.cs : Oops! Forgot to add last time. + * RootDoc.cs : Don't parse here. + * DocTreeGenerator.cs : Making it come to use. + 2003-03-28 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * RootDoc.cs : Populated all. Will take a second Index: DocTreeGenerator.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/DocTreeGenerator.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- DocTreeGenerator.cs 28 Mar 2003 10:17:40 -0000 1.4 +++ DocTreeGenerator.cs 1 Apr 2003 16:04:09 -0000 1.5 @@ -9,6 +9,7 @@ using Mono.CSharp; using System; +using System.Collections; namespace MCSDoc { @@ -17,16 +18,118 @@ private TypeContainer root; private RootDoc rootDoc; + private ArrayList allNamespaces; + private ArrayList allClasses; + private ArrayList allStructs; + private ArrayList allDelegates; + private ArrayList allEnums; + private ArrayList allInterfaces; + public DocTreeGenerator(TypeContainer root) { + if(root == null) + { + throw new ArgumentException("[DocTreeGenerator] Null root"); + } + this.root = root; - rootDoc = new RootDoc(root); - CreateTree(); + //rootDoc = new RootDoc(root); + ParseAndGenerate(); } - private void CreateTree() + private void ParseAndGenerate() { //rootDoc.Parse(root); + ParseContainers(root.Types); + ParseDelegates(root.Delegates); + ParseEnums(root.Enums); + ParseInterfaces(root.Interfaces); + //First need to populate [allNamespaces] + //GenerateTree(); + } + + private void ParseContainers(ArrayList containers) + { + if(containers != null && containers.Count > 0) + { + foreach(TypeContainer tc in containers) + { + ParseContainer(tc); + } + } + } + + private void ParseContainer(TypeContainer container) + { + if(containers != null) + { + if(container is Class) + { + Class c = (Class) container; + ClassDoc cd = null; + // Is there any better way, since + // [c.BaseType != typeof(System.Attribute)] + if(c.BaseType.ToString() == "System.Attribute") + { + cd = new AttributeDoc(c); + } else + { + cd = new ClassDoc(c); + } + allClasses.Add(cd); + } else if(container is Struct) + { + Struct s = (Struct) container; + sd = new StructDoc(s); + allStructs.Add(sd); + } + //Handle all inner types recursively + ParseContainers(container.Types); + ParseDelegates(container.Delegates); + ParseEnums(container.Enums); + ParseInterfaces(container.Interfaces); + } + } + + private void ParseDelegates(ArrayList delegates) + { + if(delegates != null && delegates.Count > 0) + { + foreach(Delegate deleg in delegates) + { + DelegateDoc dd = new DelegateDoc(deleg); + allDelegates.Add(dd); + } + } + } + + private void ParseEnums(ArrayList enums) + { + if(enums != null && enums.Count > 0) + { + foreach(Mono.CSharp.Enum eenum in enums) + { + EnumDoc ed = new EnumDoc(eenum); + allDelegates.Add(ed); + } + } + } + + private void ParseInterfaces(ArrayList interfaces) + { + if(interfaces != null && interfaces.Count > 0) + { + foreach(Interface interf in interfaces) + { + InterfaceDoc id = new InterfaceDoc(interf); + allInterfaces.Add(id); + } + } + } + + private void GenerateTree() + { + throw new NotImplementedException(); } public IRootDoc RootDoc Index: RootDoc.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/RootDoc.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- RootDoc.cs 28 Mar 2003 15:30:24 -0000 1.6 +++ RootDoc.cs 1 Apr 2003 16:04:09 -0000 1.7 @@ -26,7 +26,7 @@ public RootDoc(TypeContainer root) { - Parse(root); + //Parse(root); } private void Parse(TypeContainer root) @@ -72,8 +72,7 @@ } // process ClassDoc classes.Add(cd); - } - if(tc is Struct) + } else if(tc is Struct) { Struct s = (Struct)tc; StructDoc sd = new StructDoc(s); |
From: Gaurav V. <mas...@us...> - 2003-03-28 18:10:57
|
Update of /cvsroot/csdoc/csdoc/src/csdoc In directory sc8-pr-cvs1:/tmp/cvs-serv24871 Modified Files: ChangeLog cs-parser.jay Log Message: 2003-03-28 * cs-parser.jay : Attributes cannot be applied to namesapces. Index: ChangeLog =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/ChangeLog,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- ChangeLog 28 Mar 2003 14:29:38 -0000 1.19 +++ ChangeLog 28 Mar 2003 18:10:42 -0000 1.20 @@ -1,6 +1,11 @@ 2003-03-28 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + * cs-parser.jay : Attributes cannot be applied + to namesapces. + +2003-03-28 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + * rootcontext.cs : Set the type of AttributeTypes 2003-03-28 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> Index: cs-parser.jay =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/cs-parser.jay,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- cs-parser.jay 27 Mar 2003 17:50:51 -0000 1.7 +++ cs-parser.jay 28 Mar 2003 18:10:45 -0000 1.8 @@ -320,6 +320,10 @@ foreach (AttributeSection asec in attrs.AttributeSections) if (asec.Target == "assembly") RootContext.AddGlobalAttributeSection (current_container, asec); + else + Report.Error(1518, Lexer.Location, + "Attributes cannot be applied to namespaces." + + " Expected class, delegate, enum, interface, or struct"); } current_namespace = RootContext.Tree.RecordNamespace (current_namespace, file, (string) $3); |
From: Gaurav V. <mas...@us...> - 2003-03-28 15:30:34
|
Update of /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc In directory sc8-pr-cvs1:/tmp/cvs-serv6202 Modified Files: ChangeLog ClassDoc.cs RootDoc.cs Log Message: 2003-03-28 * RootDoc.cs : Populated all. Will take a second look sometime later, especially for PopulateInners. Have to take of if class is an attribute. * AttributeDoc.cs : Initial implementation * ClassDoc.cs : Class { get; } - Added. : Accessibility - internal. Index: ChangeLog =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/ChangeLog,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- ChangeLog 28 Mar 2003 14:23:53 -0000 1.9 +++ ChangeLog 28 Mar 2003 15:30:17 -0000 1.10 @@ -1,6 +1,15 @@ 2003-03-28 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + * RootDoc.cs : Populated all. Will take a second + look sometime later, especially for PopulateInners. + Have to take of if class is an attribute. + * AttributeDoc.cs : Initial implementation + * ClassDoc.cs : Class { get; } - Added. + : Accessibility - internal. + +2003-03-28 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + * ClassDoc.cs : Parse() - Some impl. * RootDoc.cs : PopulateTypeContainers - Init Impl. * NamespaceDoc.cs : Initial implementation. Index: ClassDoc.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/ClassDoc.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ClassDoc.cs 28 Mar 2003 14:23:55 -0000 1.3 +++ ClassDoc.cs 28 Mar 2003 15:30:22 -0000 1.4 @@ -13,7 +13,7 @@ namespace MCSDoc { - public class ClassDoc : IClassDoc + internal class ClassDoc : IClassDoc { private Class klass; private string name; @@ -42,8 +42,16 @@ */ if(klass.BaseType != null) { - isAttribute = klass.BaseType.IsSubclassOf(typeof(Attribute)); - isException = klass.BaseType.IsSubclassOf(typeof(Exception)); + isAttribute = (klass.BaseType.ToString() == "System.Attribute"); + isException = (klass.BaseType.ToString() == "System.Exception"); + } + } + + protected Class Class + { + get + { + return this.klass; } } Index: RootDoc.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/RootDoc.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- RootDoc.cs 28 Mar 2003 14:23:57 -0000 1.5 +++ RootDoc.cs 28 Mar 2003 15:30:24 -0000 1.6 @@ -49,13 +49,23 @@ { ArrayList classes = new ArrayList(); ArrayList structs = new ArrayList(); - + foreach(TypeContainer tc in containers) { if(tc is Class) { Class c = (Class)tc; - ClassDoc cd = new ClassDoc(c); + ClassDoc cd = null; + if(c.BaseType != null) + { + if(c.BaseType.ToString() == "System.Attribute") + { + cd = new AttributeDoc(c); + } + } else + { + cd = new ClassDoc(c); + } if(c.Namespace != null && c.Namespace.Name.Length > 0) { HandleNamespaceClass(c, cd); @@ -76,36 +86,48 @@ } PopulateInners(tc.Types); } + + if(classes.Count > 0) + { + this.classes = (IClassDoc[]) classes.ToArray(typeof(IClassDoc)); + } + + if(structs.Count > 0) + { + this.structs = (IClassDoc[]) classes.ToArray(typeof(IStructDoc)); + } } } private NamespaceDoc NamespaceLookup(string name) { + NamespaceDoc retVal = null; foreach(NamespaceDoc current in namespaceList) { if(current.Name == name) - return current; + { + return retVal = current; + break; + } + } + + if(retVal == null) + { + retVal = new NamespaceDoc(name); + namespaceList.Add(nsd); } - return null; + return retVal; } private void HandleNamespaceClass(Class klass, ClassDoc doc) { NamespaceDoc nsd = NamespaceLookup(klass.Namespace.Name); - if(nsd == null) - { - nsd = new NamespaceDoc(klass.Namespace.Name); - } nsd.AddClassDoc(doc); } private void HandleNamespaceStruct(Struct esstruct, StructDoc doc) { NamespaceDoc nsd = NamespaceLookup(esstruct.Namespace.Name); - if(nsd == null) - { - nsd = new NamespaceDoc(esstruct.Namespace.Name); - } nsd.AddStructDoc(doc); } @@ -116,17 +138,59 @@ private void PopulateEnums(ArrayList enums) { - throw new NotImplementedException(); + if(enums != null && enums.Count > 0) + { + ArrayList enumDocs = new ArrayList(); + EnumDoc doc; + foreach(Mono.CSharp.Enum current in enums) + { + doc = new EnumDoc(current); + enumDocs.Add(doc); + } + + if(enumDocs.Count > 0) + { + this.enums = (IEnumDoc[]) enumDocs.ToArray(typeof(IEnumDoc)); + } + } } private void PopulateDelegates(ArrayList delegates) { - throw new NotImplementedException(); + if(delegates != null && delegates.Count > 0) + { + ArrayList delegateDocs = new ArrayList(); + DelegateDoc doc; + foreach(Delegate current in delegates) + { + doc = new DelegateDoc(current); + delegateDocs.Add(doc); + } + + if(delegateDocs.Count > 0) + { + this.delegates = (IDelegateDoc[]) enumDocs.ToArray(typeof(IDelegateDoc)); + } + } } private void PopulateInterfaces(ArrayList interfaces) { - throw new NotImplementedException(); + if(interfaces != null && interfaces.Count > 0) + { + ArrayList interfaceDocs = new ArrayList(); + InterfaceDoc doc; + foreach(Interface current in interfaces) + { + doc = new DelegateDoc(current); + interfaceDocs.Add(doc); + } + + if(interfaceDocs.Count > 0) + { + this.interfaces = (IInterfaceDoc[]) enumDocs.ToArray(typeof(IInterfaceDoc)); + } + } } } } |
From: Gaurav V. <mas...@us...> - 2003-03-28 14:29:42
|
Update of /cvsroot/csdoc/csdoc/src/csdoc In directory sc8-pr-cvs1:/tmp/cvs-serv8760 Modified Files: rootcontext.cs ChangeLog Log Message: 2003-03-28 * rootcontext.cs : Set the type of AttributeTypes Index: rootcontext.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/rootcontext.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- rootcontext.cs 28 Mar 2003 14:06:26 -0000 1.2 +++ rootcontext.cs 28 Mar 2003 14:29:37 -0000 1.3 @@ -79,7 +79,7 @@ /// <remarks> /// Added by Gaurav Vaish /// </remarks> - public static AttributeTypes + public static ArrayList AttributeTypes { get { Index: ChangeLog =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/ChangeLog,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- ChangeLog 28 Mar 2003 14:22:12 -0000 1.18 +++ ChangeLog 28 Mar 2003 14:29:38 -0000 1.19 @@ -1,6 +1,10 @@ 2003-03-28 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + * rootcontext.cs : Set the type of AttributeTypes + +2003-03-28 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + * class.cs : BaseType { get; } - Added 2003-03-28 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> |
Update of /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc In directory sc8-pr-cvs1:/tmp/cvs-serv7726 Modified Files: ChangeLog ClassDoc.cs IAttributeDoc.cs IContainerDoc.cs IInterfaceDoc.cs INamespaceDoc.cs RootDoc.cs Added Files: NamespaceDoc.cs Log Message: 2003-03-28 * ClassDoc.cs : Parse() - Some impl. * RootDoc.cs : PopulateTypeContainers - Init Impl. * NamespaceDoc.cs : Initial implementation. * INamespaceDoc.cs : No Attributes to a namespace. Ok! * IAttributeDoc.cs, * IInterfaceDoc.cs, * IContainerDoc.cs : Name { get; } - Added. * IAttributeDoc.cs : Now derives from IContainerDoc --- NEW FILE --- /** * Project: Master C# Document Generator * Contact: mas...@us... * Web: http://csdoc.sourceforge.net * * Copyright: (C) 2003, Gaurav Vaish * */ using System; using System.Collections; using Mono.CSharp; namespace MCSDoc { internal class NamespaceDoc : INamespaceDoc { private string comments; private string name; ArrayList classes = new ArrayList(); ArrayList structs = new ArrayList(); ArrayList delegates = new ArrayList(); ArrayList enums = new ArrayList(); ArrayList interfaces = new ArrayList(); public NamespaceDoc(string name) { this.name = name; } public NamespaceDoc(string name, string filename) : this(name) { throw new NotImplementedException(); } public void AddClassDoc(IClassDoc doc) { classes.Add(doc); } public void AddStructDoc(IStructDoc doc) { structs.Add(doc); } public void SetDelegateDoc(IDelegateDoc doc) { delegates.Add(doc); } public void SetEnumDoc(IEnumDoc doc) { enums.Add(doc); } public void AddInterfaceDoc(IInterfaceDoc doc) { interfaces.Add(doc); } public string Comments { get { return comments; } } public IClassDoc[] Classes { get { return (IClassDoc[]) classes.ToArray(typeof(IClassDoc)); } } public IDelegateDoc[] Delegates { get { return (IDelegateDoc[]) delegates.ToArray(typeof(IDelegateDoc)); } } public IEnumDoc[] Enums { get { return (IEnumDoc[]) enums.ToArray(typeof(IEnumDoc)); } } public IInterfaceDoc[] Interfaces { get { return (IInterfaceDoc[]) interfaces.ToArray(typeof(IInterfaceDoc)); } } public IStructDoc[] Structs { get { return (IStructDoc[]) interfaces.ToArray(typeof(IStructDoc)); } } } } Index: ChangeLog =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/ChangeLog,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- ChangeLog 28 Mar 2003 10:17:40 -0000 1.8 +++ ChangeLog 28 Mar 2003 14:23:53 -0000 1.9 @@ -1,6 +1,17 @@ 2003-03-28 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + * ClassDoc.cs : Parse() - Some impl. + * RootDoc.cs : PopulateTypeContainers - Init Impl. + * NamespaceDoc.cs : Initial implementation. + * INamespaceDoc.cs : No Attributes to a namespace. Ok! + * IAttributeDoc.cs, + * IInterfaceDoc.cs, + * IContainerDoc.cs : Name { get; } - Added. + * IAttributeDoc.cs : Now derives from IContainerDoc + +2003-03-28 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + * RootDoc.cs : Stubbed PopulateXXXX methods * DocTreeGenerator.cs : Looks like won't need it in future Index: ClassDoc.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/ClassDoc.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ClassDoc.cs 27 Mar 2003 17:57:17 -0000 1.2 +++ ClassDoc.cs 28 Mar 2003 14:23:55 -0000 1.3 @@ -15,10 +15,11 @@ { public class ClassDoc : IClassDoc { - private Class klass; - private bool isException; - private bool isAttribute; - + private Class klass; + private string name; + private bool isException = false; + private bool isAttribute = false; + private IClassDoc baseClass = null; private IInterfaceDoc[] interfaces = null; private IContainerDoc container = null; @@ -29,7 +30,7 @@ // need to Set - BaseClass, Interfaces, Container throw new NotImplementedException(); } - + private void Parse() { /* @@ -39,6 +40,19 @@ // } */ + if(klass.BaseType != null) + { + isAttribute = klass.BaseType.IsSubclassOf(typeof(Attribute)); + isException = klass.BaseType.IsSubclassOf(typeof(Exception)); + } + } + + public string Name + { + get + { + return name; + } } public bool IsContained @@ -80,7 +94,7 @@ return interfaces; } } - + public IContainerDoc Container { get Index: IAttributeDoc.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/IAttributeDoc.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- IAttributeDoc.cs 22 Mar 2003 07:43:45 -0000 1.1 +++ IAttributeDoc.cs 28 Mar 2003 14:23:55 -0000 1.2 @@ -12,15 +12,9 @@ namespace MCSDoc { - public interface IAttributeDoc + public interface IAttributeDoc : IClassDoc { - string Comments { get; } - AccessFlags Flags { get; } + AccessFlags Flags { get; } AttributeTargets Targets { get; } - - IAttributeDoc[] Attributes { get; } - IMethodDoc[] Methods { get; } - IPropertyDoc[] Properties { get; } - IMemberDoc[] Members { get; } } } Index: IContainerDoc.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/IContainerDoc.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- IContainerDoc.cs 27 Mar 2003 17:57:18 -0000 1.2 +++ IContainerDoc.cs 28 Mar 2003 14:23:55 -0000 1.3 @@ -14,6 +14,7 @@ public interface IContainerDoc { string Comments { get; } + string Name { get; } AccessFlags Flags { get; } bool IsContained { get; } Index: IInterfaceDoc.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/IInterfaceDoc.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- IInterfaceDoc.cs 22 Mar 2003 07:43:45 -0000 1.1 +++ IInterfaceDoc.cs 28 Mar 2003 14:23:55 -0000 1.2 @@ -14,6 +14,7 @@ public interface IInterfaceDoc { string Comments { get; } + string Name { get; } AccessFlags Flags { get; } IAttributeDoc[] Attributes { get; } Index: INamespaceDoc.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/INamespaceDoc.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- INamespaceDoc.cs 9 Mar 2003 15:17:29 -0000 1.2 +++ INamespaceDoc.cs 28 Mar 2003 14:23:56 -0000 1.3 @@ -13,9 +13,9 @@ { public interface INamespaceDoc { - string Comments { get; } + string Comments { get; } + string Name { get; } - IAttributeDoc[] Attributes { get; } IClassDoc[] Classes { get; } IDelegateDoc[] Delegates { get; } IEnumDoc[] Enums { get; } Index: RootDoc.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/MCSDoc/RootDoc.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- RootDoc.cs 28 Mar 2003 10:17:40 -0000 1.4 +++ RootDoc.cs 28 Mar 2003 14:23:57 -0000 1.5 @@ -8,18 +8,21 @@ */ using System; +using System.Collections; using Mono.CSharp; namespace MCSDoc { internal class RootDoc : IRootDoc { - INamespaceDoc[] namespaces; - IClassDoc[] classes; - IStructDoc[] structs; - IDelegateDoc[] delegates; - IEnumDoc[] enums; - IInterfaceDoc[] interfaces; + INamespaceDoc[] namespaces = null; + IClassDoc[] classes = null; + IStructDoc[] structs = null; + IDelegateDoc[] delegates = null; + IEnumDoc[] enums = null; + IInterfaceDoc[] interfaces = null; + + ArrayList namespaceList = new ArrayList(); public RootDoc(TypeContainer root) { @@ -28,12 +31,86 @@ private void Parse(TypeContainer root) { + PopulateContainers(root.Types); throw new NotImplementedException(); } + private void PopulateNamespaces() + { + if(namespaceList.Count > 0) + { + //namespaces = (INamespaceDoc[]) namespaceList.ToArray(typeof(INamespaceDoc)); + } + } + private void PopulateContainers(ArrayList containers) { - //classes and structs + if(containers != null || containers.Count > 0) + { + ArrayList classes = new ArrayList(); + ArrayList structs = new ArrayList(); + + foreach(TypeContainer tc in containers) + { + if(tc is Class) + { + Class c = (Class)tc; + ClassDoc cd = new ClassDoc(c); + if(c.Namespace != null && c.Namespace.Name.Length > 0) + { + HandleNamespaceClass(c, cd); + } + // process ClassDoc + classes.Add(cd); + } + if(tc is Struct) + { + Struct s = (Struct)tc; + StructDoc sd = new StructDoc(s); + if(s.Namespace != null && s.Namespace.Name.Length > 0) + { + HandleNamespaceStruct(s, sd); + } + // process StructDoc + structs.Add(sd); + } + PopulateInners(tc.Types); + } + } + } + + private NamespaceDoc NamespaceLookup(string name) + { + foreach(NamespaceDoc current in namespaceList) + { + if(current.Name == name) + return current; + } + return null; + } + + private void HandleNamespaceClass(Class klass, ClassDoc doc) + { + NamespaceDoc nsd = NamespaceLookup(klass.Namespace.Name); + if(nsd == null) + { + nsd = new NamespaceDoc(klass.Namespace.Name); + } + nsd.AddClassDoc(doc); + } + + private void HandleNamespaceStruct(Struct esstruct, StructDoc doc) + { + NamespaceDoc nsd = NamespaceLookup(esstruct.Namespace.Name); + if(nsd == null) + { + nsd = new NamespaceDoc(esstruct.Namespace.Name); + } + nsd.AddStructDoc(doc); + } + + private void PopulateInners(ArrayList types) + { throw new NotImplementedException(); } |
From: Gaurav V. <mas...@us...> - 2003-03-28 14:22:22
|
Update of /cvsroot/csdoc/csdoc/src/csdoc In directory sc8-pr-cvs1:/tmp/cvs-serv6987 Modified Files: class.cs ChangeLog Log Message: 2003-03-28 * class.cs : BaseType { get; } - Added Index: class.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/class.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- class.cs 24 Feb 2003 08:33:50 -0000 1.3 +++ class.cs 28 Mar 2003 14:22:11 -0000 1.4 @@ -518,6 +518,22 @@ } } + private Type baseClassType = null; + + /// <summary> + /// Returns the type of the base class + /// </summary> + /// <remarks> + /// Added by Gaurav Vaish + /// </remarks> + public Type BaseType + { + get + { + return baseClassType; + } + } + // // Emits the instance field initializers // @@ -765,6 +781,10 @@ ec = new EmitContext (this, Mono.CSharp.Location.Null, null, null, ModFlags); ifaces = GetClassBases (is_class, out parent, out error); + if(baseClassType == null) + { + baseClassType = parent; + } if (error) return null; Index: ChangeLog =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/ChangeLog,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- ChangeLog 28 Mar 2003 14:06:29 -0000 1.17 +++ ChangeLog 28 Mar 2003 14:22:12 -0000 1.18 @@ -1,6 +1,10 @@ 2003-03-28 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + * class.cs : BaseType { get; } - Added + +2003-03-28 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + * rootcontext.cs : AttributeTypes { get; } - Added 2003-03-27 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> |
From: Gaurav V. <mas...@us...> - 2003-03-28 14:06:36
|
Update of /cvsroot/csdoc/csdoc/src/csdoc In directory sc8-pr-cvs1:/tmp/cvs-serv32124 Modified Files: rootcontext.cs ChangeLog Log Message: 2003-03-28 * rootcontext.cs : AttributeTypes { get; } - Added Index: rootcontext.cs =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/rootcontext.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- rootcontext.cs 19 Feb 2003 05:50:12 -0000 1.1 +++ rootcontext.cs 28 Mar 2003 14:06:26 -0000 1.2 @@ -72,6 +72,21 @@ type_container_resolve_order = new ArrayList (); } + /// <summary> + /// Returns all the attribute classes. + /// Individual type is TypeContainer + /// </summary> + /// <remarks> + /// Added by Gaurav Vaish + /// </remarks> + public static AttributeTypes + { + get + { + return attribute_types; + } + } + static public Tree Tree { get { return tree; Index: ChangeLog =================================================================== RCS file: /cvsroot/csdoc/csdoc/src/csdoc/ChangeLog,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- ChangeLog 27 Mar 2003 17:50:53 -0000 1.16 +++ ChangeLog 28 Mar 2003 14:06:29 -0000 1.17 @@ -1,4 +1,8 @@ +2003-03-28 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + + * rootcontext.cs : AttributeTypes { get; } - Added + 2003-03-27 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> * cs-parser.jay : Modified the attribute rule. |