ghkweon / dwscript

Automatically exported from code.google.com/p/dwscript
0 stars 0 forks source link

"Implicit uses" as a configurable option for external units #312

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
New feature: allow the coder to decide whether a TdwsUnit should be implicitly 
available to all scripts or not.

Index: Source/dwsComp.pas
===================================================================
--- Source/dwsComp.pas  (revision 1633)
+++ Source/dwsComp.pas  (working copy)
@@ -1017,6 +1017,7 @@
         FOperators : TdwsOperators;
         FTable: TUnitSymbolTable;
         FOnAfterInitUnitTable : TNotifyEvent;
+        FImplicitUse: boolean;

       protected
         FCollections : array[0..11] of TdwsCollection;
@@ -1066,6 +1067,7 @@
         procedure AddUnitSymbols(Table: TSymbolTable; operators : TOperators); override;
         procedure InitUnitTable(systemTable : TSystemSymbolTable; unitSyms : TUnitMainSymbols;
                                 operators : TOperators; UnitTable: TUnitSymbolTable); override;
+        function GetUnitFlags : TIdwsUnitFlags;

         // Method to support get/set property values for dynamicly registered classes
         procedure HandleDynamicCreate(Info: TProgramInfo; var ExtObject: TObject);
@@ -1097,6 +1099,7 @@
         property UnitName;
         property Variables: TdwsVariables read FVariables write SetVariables stored StoreVariables;
         property StaticSymbols;
+        property ImplicitUse: boolean read FImplicitUse write FImplicitUse 
stored FImplicitUse;

         property OnAfterInitUnitTable : TNotifyEvent read FOnAfterInitUnitTable write FOnAfterInitUnitTable;
    end;
@@ -1807,6 +1810,14 @@
   Result := TdwsSynonyms;
 end;

+function TdwsUnit.GetUnitFlags: TIdwsUnitFlags;
+begin
+   result := inherited GetUnitFlags;
+   if FImplicitUse then
+      include(result, ufImplicitUse)
+   else exclude(result, ufImplicitUse);
+end;
+
 // GetOperatorsClass
 //
 class function TdwsUnit.GetOperatorsClass: TdwsOperatorsClass;

Original issue reported on code.google.com by masonwhe...@gmail.com on 21 Nov 2012 at 6:40

GoogleCodeExporter commented 8 years ago
Argh.  Got the wrong version of the patch.  That won't work, and Google Code 
won't let me edit it.  Here's the correct patch:

Index: Source/dwsComp.pas
===================================================================
--- Source/dwsComp.pas  (revision 1633)
+++ Source/dwsComp.pas  (working copy)
@@ -186,7 +186,7 @@
     function GetUnitName: String; virtual;
       function GetUnitTable(systemTable : TSystemSymbolTable; unitSyms : TUnitMainSymbols;
                             operators : TOperators) : TUnitSymbolTable; virtual; abstract;
-    function GetUnitFlags : TIdwsUnitFlags;
+    function GetUnitFlags : TIdwsUnitFlags; virtual;

     property Dependencies: TStrings read FDependencies write SetDependencies;
     {$WARNINGS OFF}
@@ -1017,6 +1017,7 @@
         FOperators : TdwsOperators;
         FTable: TUnitSymbolTable;
         FOnAfterInitUnitTable : TNotifyEvent;
+        FImplicitUse: boolean;

       protected
         FCollections : array[0..11] of TdwsCollection;
@@ -1066,6 +1067,7 @@
         procedure AddUnitSymbols(Table: TSymbolTable; operators : TOperators); override;
         procedure InitUnitTable(systemTable : TSystemSymbolTable; unitSyms : TUnitMainSymbols;
                                 operators : TOperators; UnitTable: TUnitSymbolTable); override;
+        function GetUnitFlags : TIdwsUnitFlags; override;

         // Method to support get/set property values for dynamicly registered classes
         procedure HandleDynamicCreate(Info: TProgramInfo; var ExtObject: TObject);
@@ -1097,6 +1099,7 @@
         property UnitName;
         property Variables: TdwsVariables read FVariables write SetVariables stored StoreVariables;
         property StaticSymbols;
+        property ImplicitUse: boolean read FImplicitUse write FImplicitUse 
stored FImplicitUse;

         property OnAfterInitUnitTable : TNotifyEvent read FOnAfterInitUnitTable write FOnAfterInitUnitTable;
    end;
@@ -1807,6 +1810,14 @@
   Result := TdwsSynonyms;
 end;

+function TdwsUnit.GetUnitFlags: TIdwsUnitFlags;
+begin
+   result := inherited GetUnitFlags;
+   if FImplicitUse then
+      include(result, ufImplicitUse)
+   else exclude(result, ufImplicitUse);
+end;
+
 // GetOperatorsClass
 //
 class function TdwsUnit.GetOperatorsClass: TdwsOperatorsClass;

Original comment by masonwhe...@gmail.com on 21 Nov 2012 at 6:59

GoogleCodeExporter commented 8 years ago
Added

Original comment by zar...@gmail.com on 26 Nov 2012 at 3:37