Browse Source

C# drn file can be without a class

stepan-mitkin 9 months ago
parent
commit
6a15615913

+ 5 - 2
.gitignore

@@ -1,4 +1,6 @@
-
+bin
+obj
+.vs
 tmp/db2
 
 tmp/db3
@@ -13,4 +15,5 @@ tmp/no_version
 
 *~
 
-node_modules
+node_modules
+

+ 6 - 0
examples/automaton/C#/App.config

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+    <startup> 
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
+    </startup>
+</configuration>

+ 54 - 0
examples/automaton/C#/AutomataDemo.csproj

@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{19A063F3-896A-48AD-B314-2777AB15E010}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>AutomataDemo</RootNamespace>
+    <AssemblyName>AutomataDemo</AssemblyName>
+    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+    <Deterministic>true</Deterministic>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="automaton-cs.cs" />
+    <Compile Include="frog.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="App.config" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>

+ 25 - 0
examples/automaton/C#/AutomataDemo.sln

@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.28010.2016
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomataDemo", "AutomataDemo.csproj", "{19A063F3-896A-48AD-B314-2777AB15E010}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{19A063F3-896A-48AD-B314-2777AB15E010}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{19A063F3-896A-48AD-B314-2777AB15E010}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{19A063F3-896A-48AD-B314-2777AB15E010}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{19A063F3-896A-48AD-B314-2777AB15E010}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {093852F0-A0F8-493E-890B-05AA64C42F7C}
+	EndGlobalSection
+EndGlobal

+ 36 - 0
examples/automaton/C#/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("AutomataDemo")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("AutomataDemo")]
+[assembly: AssemblyCopyright("Copyright ©  2018")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components.  If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("19a063f3-896a-48ad-b314-2777ab15e010")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

BIN
examples/automaton/C#/automaton-cs.drn


+ 3 - 1
examples/automaton/C#/build

@@ -1,6 +1,8 @@
 #!/usr/bin/env bash
 rm automaton-cs.cs
+rm frong.cs
 rm automaton-cs.exe
 ../../../drakon_gen.tcl -in automaton-cs.drn
-mcs automaton-cs.cs -out:automaton-cs.exe
+../../../drakon_gen.tcl -in frog.drn
+mcs automaton-cs.cs frog.cs -out:automaton-cs.exe
 mono automaton-cs.exe

+ 95 - 0
examples/automaton/C#/frog.cs

@@ -0,0 +1,95 @@
+// Autogenerated with DRAKON Editor 1.31
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace AutomatonTest {
+
+
+
+    public partial class BabyFrog
+    {
+        
+
+        public enum StateNames {
+            Destroyed,
+            Hungry,
+            Sleepy
+        }
+
+        private StateNames _state = StateNames.Hungry;
+
+        public StateNames State {
+            get { return _state; }
+            internal set { _state = value; }
+        }
+
+        public const int FoodMessage = Frog.Food;
+        public const int SleepMessage = Frog.Sleep;
+
+        public object OnMessage(int messageType, int msg) {
+            switch (messageType) {
+                case FoodMessage:
+                    return Food(msg);
+                case SleepMessage:
+                    return Sleep(msg);
+                default:
+                    return null;
+            }
+        }
+
+        public object Food(int msg) {
+            switch (State) {
+                case StateNames.Hungry:
+                    return Hungry_Food(msg);
+                case StateNames.Sleepy:
+                    return Sleepy_Food(msg);
+                default:
+                    return null;
+            }
+        }
+
+        public object Sleep(int msg) {
+            switch (State) {
+                case StateNames.Hungry:
+                    return Hungry_Sleep(msg);
+                case StateNames.Sleepy:
+                    return Sleepy_Sleep(msg);
+                default:
+                    return null;
+            }
+        }
+
+        private object Hungry_Food(int msg) {
+            // item 14
+            State = StateNames.Sleepy;
+            return "yam-yam";
+        }
+
+        private object Hungry_Sleep(int msg) {
+            // item 23
+            State = StateNames.Hungry;
+            return "I am hungry";
+        }
+
+        private object Sleepy_Food(int msg) {
+            // item 25
+            State = StateNames.Sleepy;
+            return "na...";
+        }
+
+        private object Sleepy_Sleep(int msg) {
+            // item 29
+            State = StateNames.Hungry;
+            return "z-z-z...";
+        }
+
+        public void Shutdown() {
+            if (State == StateNames.Destroyed) {
+                return;
+            }
+            State = StateNames.Destroyed;
+            
+        }
+    }
+}

BIN
examples/automaton/C#/frog.drn


BIN
generators/cs.drn


+ 42 - 12
generators/cs.tcl

@@ -649,15 +649,39 @@ proc generate { db gdb filename } {
         set nogoto 1
         set all_functions [ gen::generate_functions \
          $db $gdb $callbacks $nogoto ]
-        #item 734
-        if {$class == ""} {
-            #item 735
-            error \
-            "Please add the ===class=== section to the file description."
+        #item 338
+        if {[ graph::errors_occured ]} {
+            
         } else {
-            #item 338
-            if {[ graph::errors_occured ]} {
-                
+            #item 1917
+            if {$class == ""} {
+                #item 1920
+                set class_name ""
+                #item 1254
+                separate_methods $gdb $all_functions functions methods
+                #item 1587
+                set machines [ add_handlers $gdb $raw_machines \
+                 $all_functions ]
+                #item 339
+                set hfile [ replace_extension $filename "cs" ]
+                set fhandle [ open_output_file $hfile ]
+                catch {
+                	p.print_to_file $fhandle $functions \
+                		$methods \
+                		$header $class $class_name $footer \
+                		$machines
+                } error_message
+                set details $::errorInfo
+                catch { close $fhandle }
+                #item 340
+                if {$error_message == ""} {
+                    
+                } else {
+                    #item 1253
+                    puts $details
+                    #item 341
+                    error $error_message
+                }
             } else {
                 #item 927
                 set class_name [ extract_class_name $class ]
@@ -1282,8 +1306,13 @@ proc p.print_to_file { fhandle functions methods header class class_name footer
     print_procs 0 $fhandle $protected "" 1
     print_procs 0 $fhandle $private "" 1
     print_procs 0 $fhandle $none "" 1
-    #item 76
-    puts $fhandle "\}"
+    #item 1921
+    if {$class_name == ""} {
+        
+    } else {
+        #item 76
+        puts $fhandle "\}"
+    }
     #item 1068
     puts $fhandle $footer
 }
@@ -1368,6 +1397,7 @@ proc print_machine { fhandle machine } {
         set params [ join $real_params ", " ]
         #item 1844
         set pnames [ lrange $param_names 1 end ]
+        set pnames_str [ join $pnames ", " ]
         #item 1843
         set arg_name_list [ join $pnames ", " ]
         #item 1878
@@ -1400,7 +1430,7 @@ proc print_machine { fhandle machine } {
         puts $fhandle ""
         puts $fhandle "        public StateNames State \{"
         puts $fhandle "            get \{ return _state; \}"
-        puts $fhandle "            private set \{ _state = value; \}"
+        puts $fhandle "            internal set \{ _state = value; \}"
         puts $fhandle "        \}"
         #item 1846
         puts $fhandle ""
@@ -1429,7 +1459,7 @@ proc print_machine { fhandle machine } {
             #item 1740
             puts $fhandle "                case ${message}Message:"
             #item 1842
-            puts $fhandle "                    return ${message}\($pnames\);"
+            puts $fhandle "                    return ${message}\($pnames_str\);"
         }
         #item 1739
         puts $fhandle "                default:"