пятница, 15 апреля 2016 г.

#1222. Скрипты. Функция преобразующая элемент в константный массив из одного (этого) элемента

Функция преобразующая элемент в константный массив из одного (этого) элемента.

И кеширующая результат выполнения.

ModelElement elem_func WeakRef
 %SUMMARY 
  'Возвращает СЛАБУЮ ссылку на элемент.'
 ;
 RULES
  ( Self IsIntf )
   ( Self pop:WordBox:Boxed )
  DEFAULT
   Self 
 ; // RULES
 >>> Result
; // WeakRef

WordAlias [[ [
%REMARK 'Начинает определение константного массива. Пока просто мапируется на неконстантный.'
WordAlias ]] ]
%REMARK 'Заканчивает определение константного массива. Пока просто мапируется на неконстантный.'

ARRAY elem_func ElementToArray
 Cached:
 (
  [[ Self .WeakRef ]]
 ) 
 >>> Result 
; // ElementToArray

ARRAY elem_func ElementToArray:
  ^ IN aLambda
 Self aLambda DO .ElementToArray
 >>> Result 
; // ElementToArray:

Используется для оптимизации расхода памяти.
Массивы создаются не каждый раз при вызове функции, а один раз на элемент.

И вызов:

elem_proc OutClass

 Self .DefineImplementedMixInValues

 if ( Self .UPisTrue "need UC" ) then
 begin
  Self .UserCode: 'ci' ()
 end // ( Self .UPisTrue "need UC" ) 

 Self .MixInValues .for> (
   IN aValue
  aValue .Name array:AddTo g_MixInValues 
  [ '_' aValue .Name '_' ' = ' aValue .Target .TypeName ';' ] .Out
 )
 
 VAR l_Parent
 Self .CalcParentAndInclude >>> l_Parent
 
 if ( Self .UPisTrue "need UC" ) then
 begin
  Self .UserCode: 'cit' ()
 end // ( Self .UPisTrue "need UC" ) 
 
 [ 
  Self .TypeName 
  ' = ' 
  
  Self .Abstraction CASE
   at_abstract
    [ cOpenComment 'abstract' cCloseComment cSpace ]
   at_final
    [ cOpenComment 'final' cCloseComment cSpace ]
  END // CASE
  
  'class'

  ARRAY VAR l_Implements 
  [] >>> l_Implements

  VAR l_WasComma
  false >>> l_WasComma
  
  l_Parent .ElementToArray
  .join> ( 
   Self .ClassImplements 
   .filter> (
     IN anItem
    if ( anItem l_Implements array:Has ! ) then
    begin
     anItem array:AddTo l_Implements
     true
    end // ( anItem l_Implements array:Has ! )
    else
    begin
     false
    end // ( anItem l_Implements array:Has ! )
   ) // .filter>
  ) // .join>
  .With()> (
    IN anItem
   RULES 
    ( anItem .IsMixIn )
     ( anItem .TypeName .WithComma: l_WasComma .KeepInStack )
    DEFAULT
    begin
     anItem .IfDefBraceLn:
     ( 
      anItem .TypeName .WithComma: l_WasComma .KeepInStack
     ) // anItem .IfDefBraceLn:
    end // DEFAULT
   ; // RULES
  ) // .With()>
 ] .Out
 
 Self .OutDocumentation
 Self .OutClassInner
 
 [ 'end;//' Self .TypeName ] .Out
 
 Self .UndefineImplementedMixInValues
; // OutClass

четверг, 7 апреля 2016 г.

#1220. Последний штрих на сегодня. Определяем, что такого элемента ещё нет

Последний штрих на сегодня.

Определяем, что такого элемента ещё нет:

elem_iterator ConstantsEx
 Cached:
 (
  Self .Constants
  
  RULES
   ( Self .IsTypedef )
    begin
     VAR l_OtherEnum
     Self .MainAncestor >>> l_OtherEnum
     RULES
      ( l_OtherEnum .IsEnum )
       RULES
        ( Self .Name l_OtherEnum .Name == )
         RULES
          ( l_OtherEnum .Attributes .CountIt > 0 )
           begin
            VAR l_ConstantsName
            [ Self .Name '_' l_OtherEnum .Name '_' 'Constants' ] strings:Cat >>> l_ConstantsName
            RULES
             ( 
              Self .Parent call.me 
              .filter> ( .Name l_ConstantsName == )
              .CountIt 0 ==
             )
              begin
               .join>
               [
                l_ConstantsName MakeConstants: (
                  IN aConstants
                 aConstants -> %SUM := ( [ 'Алиасы для значений ' l_OtherEnum .Parent .Name '.' l_OtherEnum .Name ] strings:Cat )
                 aConstants -> Visibility := PublicAccess
                 VAR l_ElementPrefix
                 l_OtherEnum .GetUP 'extprop:pas:ElementPrefix' >>> l_ElementPrefix
                 aConstants -> Attributes := [
                  l_OtherEnum .Attributes .for> (
                    IN anItem
                   VAR l_Name 
                   [ l_ElementPrefix anItem .Name ] strings:Cat >>> l_Name
                   l_Name
                   [ l_OtherEnum .EffectiveUnitName '.' l_Name ] strings:Cat 
                   MakeConstant: (
                     IN aConstant
                    RULES
                     ( anItem .Documentation IsNil ! )
                      ( aConstant -> %SUM := ( anItem .Documentation ) )
                    ; // RULES 
                   ) // MakeConstant:
                  ) // l_OtherEnum .Attributes .for>
                 ] // aConstants -> Attributes
                ) // MakeConstants:
               ] // .join>
              end
            ; // RULES
           end // ( l_OtherEnum .Attributes .CountIt > 0 )
         ; // RULES
       ; // RULES
     ; // RULES
    end // ( Self .IsTypedef )
  ; // RULES
 )
 >>> Result
; // ConstantsEx

#1219. Скрипты. Продолжаем тему

INTERFACE FUNCTION MakeConstants:
  STRING IN aName
  ^ IN aLambda
 aName nil MakeParam: ( 
   IN aMade
  aMade -> Stereotype := st_Constants
  aMade aLambda DO
 )
 >>> Result 
; // MakeConstants:
  
INTERFACE FUNCTION MakeConstant:
  STRING IN aName
  PRINTABLE IN aValue
  ^ IN aLambda
 aName nil MakeParam: ( 
   IN aMade
  aMade -> Class := class_Attribute
  aMade -> 'extprop:pas:Value' := aValue
  aMade aLambda DO
 )
 >>> Result 
; // MakeConstant:

elem_iterator ConstantsEx
 Cached:
 (
  Self .Constants
  
  RULES
   ( Self .IsTypedef )
    begin
     VAR l_OtherEnum
     Self .MainAncestor >>> l_OtherEnum
     RULES
      ( l_OtherEnum .IsEnum )
       RULES
        ( Self .Name l_OtherEnum .Name == )
         RULES
          ( l_OtherEnum .Attributes .CountIt > 0 )
           begin
            VAR l_ConstantsName
            [ Self .Name '_' l_OtherEnum .Name '_' 'Constants' ] strings:Cat >>> l_ConstantsName
            .join>
            [
             l_ConstantsName MakeConstants: (
               IN aConstants
              aConstants -> %SUM := ( [ 'Алиасы для значений ' l_OtherEnum .Parent .Name '.' l_OtherEnum .Name ] strings:Cat )
              aConstants -> Visibility := PublicAccess
              aConstants -> Attributes := [
               l_OtherEnum .Attributes .for> (
                 IN anItem
                anItem .Name 
                [ l_OtherEnum .EffectiveUnitName '.' anItem .Name ] strings:Cat 
                MakeConstant: (
                  IN aConstant
                 RULES
                  ( anItem .Documentation IsNil ! )
                   ( aConstant -> %SUM := ( anItem .Documentation ) )
                 ; // RULES 
                ) // MakeConstant:
               ) // l_OtherEnum .Attributes .for>
              ] // aConstants -> Attributes
             ) // MakeConstants:
            ] // .join>
           end // ( l_OtherEnum .Attributes .CountIt > 0 )
         ; // RULES
       ; // RULES
     ; // RULES
    end // ( Self .IsTypedef )
  ; // RULES
 )
 >>> Result
; // ConstantsEx

К коду нужны комментарии?

#1218. Скрипты. Правила. Итераторы. Лямбды. Списки. Добавление элементов. Продолжение темы

INTERFACE FUNCTION MakeConstants:
  STRING IN aName
  ^ IN aLambda
 aName nil MakeParam: ( 
   IN aMade
  aMade -> Stereotype := st_Constants
  aMade aLambda DO
 )
 >>> Result 
; // MakeConstants:
  
INTERFACE FUNCTION MakeConstant:
  STRING IN aName
  PRINTABLE IN aValue
  ^ IN aLambda
 aName nil MakeParam: ( 
   IN aMade
  aMade -> Class := class_Attribute
  aMade -> 'extprop:pas:Value' := aValue
  aMade aLambda DO
 )
 >>> Result 
; // MakeConstant:

elem_iterator ConstantsEx
 Cached:
 (
  Self .Constants
  
  RULES
   ( Self .IsTypedef )
    begin
     VAR l_OtherEnum
     Self .MainAncestor >>> l_OtherEnum
     RULES
      ( l_OtherEnum .IsEnum )
       RULES
        ( Self .Name l_OtherEnum .Name == )
         RULES
          ( l_OtherEnum .Attributes .CountIt > 0 )
           begin
            VAR l_ConstantsName
            [ Self .Name '_' l_OtherEnum .Name '_' 'Constants' ] strings:Cat >>> l_ConstantsName
            .join>
            [
             l_ConstantsName MakeConstants: (
               IN aConstants
              aConstants -> %SUM := ( [ 'Алиасы для значений ' l_OtherEnum .Parent .Name '.' l_OtherEnum .Name ] strings:Cat )
              aConstants -> Visibility := PublicAccess
              aConstants -> Attributes := [
               l_OtherEnum .Attributes .for> (
                 IN anItem
                anItem .Name 'XXX' MakeConstant: (
                  IN aConstant
                ) // MakeConstant:
               ) // l_OtherEnum .Attributes .for>
              ] // aConstants -> Attributes
             ) // MakeConstants:
            ] // .join>
           end // ( l_OtherEnum .Attributes .CountIt > 0 )
         ; // RULES
       ; // RULES
     ; // RULES
    end // ( Self .IsTypedef )
  ; // RULES
 )
 >>> Result
; // ConstantsEx

#1217. Скрипты. Правила. Продолжение темы

elem_iterator ConstantsEx
 Cached:
 (
  Self .Constants
  
  RULES
   ( Self .IsTypedef )
    begin
     VAR l_OtherEnum
     Self .MainAncestor >>> l_OtherEnum
     RULES
      ( l_OtherEnum .IsEnum )
       RULES
        ( Self .Name l_OtherEnum .Name == )
         RULES
          ( l_OtherEnum .Attributes .CountIt > 0 )
           begin
            .join>
            [
             [ Self .Name '_' l_OtherEnum .Name '_' 'Constants' ] strings:Cat
             MakeConstants: (
               IN aConstants
              aConstants -> %SUM := ( [ 'Алиасы для значений ' l_OtherEnum .Parent .Name '.' l_OtherEnum .Name ] strings:Cat )
              aConstants -> Visibility := PublicAccess
              aConstants .Name Msg 
              aConstants .Documentation Msg 
             ) // MakeConstants:
            ]
           end // ( l_OtherEnum .Attributes .CountIt > 0 )
         ; // RULES
       ; // RULES
     ; // RULES
    end // ( Self .IsTypedef )
  ; // RULES
 )
 >>> Result
; // ConstantsEx

#1216. Скрипты. Правила. Создание новых элементов. Лямбды. Объединение списков

INTERFACE FUNCTION MakeConstants:
  STRING IN aName
  ^ IN aLambda
 aName nil MakeParam: ( 
   IN aMade
  aMade -> Stereotype := st_Constants
  aMade aLambda DO
 )
 >>> Result 
; // MakeConstants:
  
elem_iterator ConstantsEx
 Cached:
 (
  Self .Constants
  
  RULES
   ( Self .IsTypedef )
    RULES
     ( Self .MainAncestor .IsEnum )
      RULES
       ( Self .Name Self .MainAncestor .Name == )
        (
         .join>
         [
          [ Self .Name '_' Self .MainAncestor .Name '_' 'Constants' ] strings:Cat
          MakeConstants: (
            IN aConstants
           aConstants .Name Msg 
          ) // MakeConstants:
         ]
        ) // ( Self .Name Self .MainAncestor .Name == )
      ; // RULES
    ; // RULES
  ; // RULES
 )
 >>> Result
; // ConstantsEx