IncludeCPP 3.5.0__py3-none-any.whl → 3.7.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- includecpp/__init__.py +1 -1
- includecpp/cli/commands.py +418 -0
- includecpp/core/cssl/CSSL_DOCUMENTATION.md +613 -20
- includecpp/core/cssl/cssl_builtins.py +342 -2
- includecpp/core/cssl/cssl_builtins.pyi +1393 -0
- includecpp/core/cssl/cssl_parser.py +368 -64
- includecpp/core/cssl/cssl_runtime.py +637 -38
- includecpp/core/cssl/cssl_types.py +561 -2
- includecpp/core/cssl_bridge.py +100 -4
- includecpp/core/cssl_bridge.pyi +177 -0
- includecpp/vscode/cssl/package.json +24 -4
- includecpp/vscode/cssl/snippets/cssl.snippets.json +1080 -0
- includecpp/vscode/cssl/syntaxes/cssl.tmLanguage.json +127 -7
- {includecpp-3.5.0.dist-info → includecpp-3.7.1.dist-info}/METADATA +1 -1
- {includecpp-3.5.0.dist-info → includecpp-3.7.1.dist-info}/RECORD +19 -17
- {includecpp-3.5.0.dist-info → includecpp-3.7.1.dist-info}/WHEEL +0 -0
- {includecpp-3.5.0.dist-info → includecpp-3.7.1.dist-info}/entry_points.txt +0 -0
- {includecpp-3.5.0.dist-info → includecpp-3.7.1.dist-info}/licenses/LICENSE +0 -0
- {includecpp-3.5.0.dist-info → includecpp-3.7.1.dist-info}/top_level.txt +0 -0
|
@@ -546,16 +546,300 @@ class Array(list):
|
|
|
546
546
|
return len(self)
|
|
547
547
|
|
|
548
548
|
|
|
549
|
+
class List(list):
|
|
550
|
+
"""Python-like list with all standard operations.
|
|
551
|
+
|
|
552
|
+
Works exactly like Python lists with additional CSSL methods.
|
|
553
|
+
|
|
554
|
+
Usage:
|
|
555
|
+
list myList;
|
|
556
|
+
myList.append("item");
|
|
557
|
+
myList.insert(0, "first");
|
|
558
|
+
myList.pop();
|
|
559
|
+
myList.find("item"); # Returns index or -1
|
|
560
|
+
"""
|
|
561
|
+
|
|
562
|
+
def __init__(self, element_type: str = 'dynamic'):
|
|
563
|
+
super().__init__()
|
|
564
|
+
self._element_type = element_type
|
|
565
|
+
|
|
566
|
+
def length(self) -> int:
|
|
567
|
+
"""Return list length"""
|
|
568
|
+
return len(self)
|
|
569
|
+
|
|
570
|
+
def size(self) -> int:
|
|
571
|
+
"""Return list size (alias for length)"""
|
|
572
|
+
return len(self)
|
|
573
|
+
|
|
574
|
+
def isEmpty(self) -> bool:
|
|
575
|
+
"""Check if list is empty"""
|
|
576
|
+
return len(self) == 0
|
|
577
|
+
|
|
578
|
+
def first(self) -> Any:
|
|
579
|
+
"""Get first element"""
|
|
580
|
+
return self[0] if self else None
|
|
581
|
+
|
|
582
|
+
def last(self) -> Any:
|
|
583
|
+
"""Get last element"""
|
|
584
|
+
return self[-1] if self else None
|
|
585
|
+
|
|
586
|
+
def at(self, index: int) -> Any:
|
|
587
|
+
"""Get item at index (safe access)"""
|
|
588
|
+
if 0 <= index < len(self):
|
|
589
|
+
return self[index]
|
|
590
|
+
return None
|
|
591
|
+
|
|
592
|
+
def set(self, index: int, value: Any) -> 'List':
|
|
593
|
+
"""Set item at index"""
|
|
594
|
+
if 0 <= index < len(self):
|
|
595
|
+
self[index] = value
|
|
596
|
+
return self
|
|
597
|
+
|
|
598
|
+
def add(self, item: Any) -> 'List':
|
|
599
|
+
"""Add item to end (alias for append)"""
|
|
600
|
+
self.append(item)
|
|
601
|
+
return self
|
|
602
|
+
|
|
603
|
+
def push(self, item: Any) -> 'List':
|
|
604
|
+
"""Push item to end (alias for append)"""
|
|
605
|
+
self.append(item)
|
|
606
|
+
return self
|
|
607
|
+
|
|
608
|
+
def find(self, item: Any) -> int:
|
|
609
|
+
"""Find index of item (-1 if not found)"""
|
|
610
|
+
try:
|
|
611
|
+
return self.index(item)
|
|
612
|
+
except ValueError:
|
|
613
|
+
return -1
|
|
614
|
+
|
|
615
|
+
def contains(self, item: Any) -> bool:
|
|
616
|
+
"""Check if list contains item"""
|
|
617
|
+
return item in self
|
|
618
|
+
|
|
619
|
+
def indexOf(self, item: Any) -> int:
|
|
620
|
+
"""Find index of item (-1 if not found)"""
|
|
621
|
+
return self.find(item)
|
|
622
|
+
|
|
623
|
+
def lastIndexOf(self, item: Any) -> int:
|
|
624
|
+
"""Find last index of item (-1 if not found)"""
|
|
625
|
+
for i in range(len(self) - 1, -1, -1):
|
|
626
|
+
if self[i] == item:
|
|
627
|
+
return i
|
|
628
|
+
return -1
|
|
629
|
+
|
|
630
|
+
def removeAt(self, index: int) -> Any:
|
|
631
|
+
"""Remove and return item at index"""
|
|
632
|
+
if 0 <= index < len(self):
|
|
633
|
+
return self.pop(index)
|
|
634
|
+
return None
|
|
635
|
+
|
|
636
|
+
def removeValue(self, value: Any) -> bool:
|
|
637
|
+
"""Remove first occurrence of value"""
|
|
638
|
+
try:
|
|
639
|
+
self.remove(value)
|
|
640
|
+
return True
|
|
641
|
+
except ValueError:
|
|
642
|
+
return False
|
|
643
|
+
|
|
644
|
+
def removeAll(self, value: Any) -> int:
|
|
645
|
+
"""Remove all occurrences of value, return count"""
|
|
646
|
+
count = 0
|
|
647
|
+
while value in self:
|
|
648
|
+
self.remove(value)
|
|
649
|
+
count += 1
|
|
650
|
+
return count
|
|
651
|
+
|
|
652
|
+
def slice(self, start: int, end: int = None) -> 'List':
|
|
653
|
+
"""Return slice of list"""
|
|
654
|
+
result = List(self._element_type)
|
|
655
|
+
if end is None:
|
|
656
|
+
result.extend(self[start:])
|
|
657
|
+
else:
|
|
658
|
+
result.extend(self[start:end])
|
|
659
|
+
return result
|
|
660
|
+
|
|
661
|
+
def join(self, separator: str = ',') -> str:
|
|
662
|
+
"""Join elements into string"""
|
|
663
|
+
return separator.join(str(item) for item in self)
|
|
664
|
+
|
|
665
|
+
def unique(self) -> 'List':
|
|
666
|
+
"""Return list with unique elements"""
|
|
667
|
+
result = List(self._element_type)
|
|
668
|
+
seen = set()
|
|
669
|
+
for item in self:
|
|
670
|
+
key = item if isinstance(item, (int, str, float, bool)) else id(item)
|
|
671
|
+
if key not in seen:
|
|
672
|
+
seen.add(key)
|
|
673
|
+
result.append(item)
|
|
674
|
+
return result
|
|
675
|
+
|
|
676
|
+
def sorted(self, reverse: bool = False) -> 'List':
|
|
677
|
+
"""Return sorted copy"""
|
|
678
|
+
result = List(self._element_type)
|
|
679
|
+
result.extend(sorted(self, reverse=reverse))
|
|
680
|
+
return result
|
|
681
|
+
|
|
682
|
+
def reversed(self) -> 'List':
|
|
683
|
+
"""Return reversed copy"""
|
|
684
|
+
result = List(self._element_type)
|
|
685
|
+
result.extend(reversed(self))
|
|
686
|
+
return result
|
|
687
|
+
|
|
688
|
+
def shuffle(self) -> 'List':
|
|
689
|
+
"""Shuffle list in place"""
|
|
690
|
+
import random
|
|
691
|
+
random.shuffle(self)
|
|
692
|
+
return self
|
|
693
|
+
|
|
694
|
+
def fill(self, value: Any, count: int = None) -> 'List':
|
|
695
|
+
"""Fill list with value"""
|
|
696
|
+
if count is None:
|
|
697
|
+
for i in range(len(self)):
|
|
698
|
+
self[i] = value
|
|
699
|
+
else:
|
|
700
|
+
self.clear()
|
|
701
|
+
self.extend([value] * count)
|
|
702
|
+
return self
|
|
703
|
+
|
|
704
|
+
def begin(self) -> int:
|
|
705
|
+
"""Return iterator to beginning"""
|
|
706
|
+
return 0
|
|
707
|
+
|
|
708
|
+
def end(self) -> int:
|
|
709
|
+
"""Return iterator to end"""
|
|
710
|
+
return len(self)
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
class Dictionary(dict):
|
|
714
|
+
"""Python-like dictionary with all standard operations.
|
|
715
|
+
|
|
716
|
+
Works exactly like Python dicts with additional CSSL methods.
|
|
717
|
+
|
|
718
|
+
Usage:
|
|
719
|
+
dictionary myDict;
|
|
720
|
+
myDict.set("key", "value");
|
|
721
|
+
myDict.get("key");
|
|
722
|
+
myDict.keys();
|
|
723
|
+
myDict.values();
|
|
724
|
+
"""
|
|
725
|
+
|
|
726
|
+
def __init__(self, key_type: str = 'dynamic', value_type: str = 'dynamic'):
|
|
727
|
+
super().__init__()
|
|
728
|
+
self._key_type = key_type
|
|
729
|
+
self._value_type = value_type
|
|
730
|
+
|
|
731
|
+
def length(self) -> int:
|
|
732
|
+
"""Return dictionary size"""
|
|
733
|
+
return len(self)
|
|
734
|
+
|
|
735
|
+
def size(self) -> int:
|
|
736
|
+
"""Return dictionary size (alias for length)"""
|
|
737
|
+
return len(self)
|
|
738
|
+
|
|
739
|
+
def isEmpty(self) -> bool:
|
|
740
|
+
"""Check if dictionary is empty"""
|
|
741
|
+
return len(self) == 0
|
|
742
|
+
|
|
743
|
+
def set(self, key: Any, value: Any) -> 'Dictionary':
|
|
744
|
+
"""Set key-value pair"""
|
|
745
|
+
self[key] = value
|
|
746
|
+
return self
|
|
747
|
+
|
|
748
|
+
def hasKey(self, key: Any) -> bool:
|
|
749
|
+
"""Check if key exists"""
|
|
750
|
+
return key in self
|
|
751
|
+
|
|
752
|
+
def hasValue(self, value: Any) -> bool:
|
|
753
|
+
"""Check if value exists"""
|
|
754
|
+
return value in self.values()
|
|
755
|
+
|
|
756
|
+
def remove(self, key: Any) -> Any:
|
|
757
|
+
"""Remove and return value for key"""
|
|
758
|
+
return self.pop(key, None)
|
|
759
|
+
|
|
760
|
+
def getOrDefault(self, key: Any, default: Any = None) -> Any:
|
|
761
|
+
"""Get value or default if not found"""
|
|
762
|
+
return self.get(key, default)
|
|
763
|
+
|
|
764
|
+
def setDefault(self, key: Any, default: Any) -> Any:
|
|
765
|
+
"""Set default if key doesn't exist, return value"""
|
|
766
|
+
if key not in self:
|
|
767
|
+
self[key] = default
|
|
768
|
+
return self[key]
|
|
769
|
+
|
|
770
|
+
def merge(self, other: dict) -> 'Dictionary':
|
|
771
|
+
"""Merge another dictionary into this one"""
|
|
772
|
+
self.update(other)
|
|
773
|
+
return self
|
|
774
|
+
|
|
775
|
+
def keysList(self) -> list:
|
|
776
|
+
"""Return keys as list"""
|
|
777
|
+
return list(self.keys())
|
|
778
|
+
|
|
779
|
+
def valuesList(self) -> list:
|
|
780
|
+
"""Return values as list"""
|
|
781
|
+
return list(self.values())
|
|
782
|
+
|
|
783
|
+
def itemsList(self) -> list:
|
|
784
|
+
"""Return items as list of tuples"""
|
|
785
|
+
return list(self.items())
|
|
786
|
+
|
|
787
|
+
def filter(self, predicate: Callable[[Any, Any], bool]) -> 'Dictionary':
|
|
788
|
+
"""Filter dictionary by predicate(key, value)"""
|
|
789
|
+
result = Dictionary(self._key_type, self._value_type)
|
|
790
|
+
for k, v in self.items():
|
|
791
|
+
if predicate(k, v):
|
|
792
|
+
result[k] = v
|
|
793
|
+
return result
|
|
794
|
+
|
|
795
|
+
def map(self, func: Callable[[Any, Any], Any]) -> 'Dictionary':
|
|
796
|
+
"""Apply function to all values"""
|
|
797
|
+
result = Dictionary(self._key_type, self._value_type)
|
|
798
|
+
for k, v in self.items():
|
|
799
|
+
result[k] = func(k, v)
|
|
800
|
+
return result
|
|
801
|
+
|
|
802
|
+
def forEach(self, func: Callable[[Any, Any], None]) -> 'Dictionary':
|
|
803
|
+
"""Execute function for each key-value pair"""
|
|
804
|
+
for k, v in self.items():
|
|
805
|
+
func(k, v)
|
|
806
|
+
return self
|
|
807
|
+
|
|
808
|
+
def invert(self) -> 'Dictionary':
|
|
809
|
+
"""Swap keys and values"""
|
|
810
|
+
result = Dictionary(self._value_type, self._key_type)
|
|
811
|
+
for k, v in self.items():
|
|
812
|
+
result[v] = k
|
|
813
|
+
return result
|
|
814
|
+
|
|
815
|
+
def find(self, value: Any) -> Optional[Any]:
|
|
816
|
+
"""Find first key with given value"""
|
|
817
|
+
for k, v in self.items():
|
|
818
|
+
if v == value:
|
|
819
|
+
return k
|
|
820
|
+
return None
|
|
821
|
+
|
|
822
|
+
def findAll(self, value: Any) -> list:
|
|
823
|
+
"""Find all keys with given value"""
|
|
824
|
+
return [k for k, v in self.items() if v == value]
|
|
825
|
+
|
|
826
|
+
|
|
549
827
|
class Shuffled(list):
|
|
550
828
|
"""Unorganized fast storage for multiple returns.
|
|
551
829
|
|
|
552
830
|
Stores data unorganized for fast and efficient access.
|
|
553
831
|
Supports receiving multiple return values from functions.
|
|
832
|
+
Can be used as a function modifier to allow multiple returns.
|
|
554
833
|
|
|
555
834
|
Usage:
|
|
556
835
|
shuffled<string> results;
|
|
557
836
|
results +<== someFunc(); # Catches all returns
|
|
558
837
|
results.read() # Returns all content as list
|
|
838
|
+
|
|
839
|
+
# As return modifier:
|
|
840
|
+
shuffled string getData() {
|
|
841
|
+
return "name", "address"; # Returns multiple values
|
|
842
|
+
}
|
|
559
843
|
"""
|
|
560
844
|
|
|
561
845
|
def __init__(self, element_type: str = 'dynamic'):
|
|
@@ -575,6 +859,49 @@ class Shuffled(list):
|
|
|
575
859
|
self.append(result)
|
|
576
860
|
return self
|
|
577
861
|
|
|
862
|
+
def add(self, *items) -> 'Shuffled':
|
|
863
|
+
"""Add one or more items"""
|
|
864
|
+
for item in items:
|
|
865
|
+
if isinstance(item, (list, tuple)):
|
|
866
|
+
self.extend(item)
|
|
867
|
+
else:
|
|
868
|
+
self.append(item)
|
|
869
|
+
return self
|
|
870
|
+
|
|
871
|
+
def first(self) -> Any:
|
|
872
|
+
"""Get first element"""
|
|
873
|
+
return self[0] if self else None
|
|
874
|
+
|
|
875
|
+
def last(self) -> Any:
|
|
876
|
+
"""Get last element"""
|
|
877
|
+
return self[-1] if self else None
|
|
878
|
+
|
|
879
|
+
def length(self) -> int:
|
|
880
|
+
"""Return shuffled length"""
|
|
881
|
+
return len(self)
|
|
882
|
+
|
|
883
|
+
def isEmpty(self) -> bool:
|
|
884
|
+
"""Check if empty"""
|
|
885
|
+
return len(self) == 0
|
|
886
|
+
|
|
887
|
+
def contains(self, item: Any) -> bool:
|
|
888
|
+
"""Check if contains item"""
|
|
889
|
+
return item in self
|
|
890
|
+
|
|
891
|
+
def at(self, index: int) -> Any:
|
|
892
|
+
"""Get item at index"""
|
|
893
|
+
if 0 <= index < len(self):
|
|
894
|
+
return self[index]
|
|
895
|
+
return None
|
|
896
|
+
|
|
897
|
+
def toList(self) -> list:
|
|
898
|
+
"""Convert to plain list"""
|
|
899
|
+
return list(self)
|
|
900
|
+
|
|
901
|
+
def toTuple(self) -> tuple:
|
|
902
|
+
"""Convert to tuple"""
|
|
903
|
+
return tuple(self)
|
|
904
|
+
|
|
578
905
|
|
|
579
906
|
class Iterator:
|
|
580
907
|
"""Advanced iterator with programmable tasks.
|
|
@@ -944,10 +1271,242 @@ def create_array(element_type: str = 'dynamic') -> Array:
|
|
|
944
1271
|
return Array(element_type)
|
|
945
1272
|
|
|
946
1273
|
|
|
1274
|
+
def create_list(element_type: str = 'dynamic') -> List:
|
|
1275
|
+
"""Create a List object"""
|
|
1276
|
+
return List(element_type)
|
|
1277
|
+
|
|
1278
|
+
|
|
1279
|
+
def create_dictionary(key_type: str = 'dynamic', value_type: str = 'dynamic') -> Dictionary:
|
|
1280
|
+
"""Create a Dictionary object"""
|
|
1281
|
+
return Dictionary(key_type, value_type)
|
|
1282
|
+
|
|
1283
|
+
|
|
1284
|
+
class Map(dict):
|
|
1285
|
+
"""C++ style map container with ordered key-value pairs.
|
|
1286
|
+
|
|
1287
|
+
Similar to Dictionary but with C++ map semantics.
|
|
1288
|
+
Keys are maintained in sorted order.
|
|
1289
|
+
|
|
1290
|
+
Usage:
|
|
1291
|
+
map<string, int> ages;
|
|
1292
|
+
ages.insert("Alice", 30);
|
|
1293
|
+
ages.find("Alice");
|
|
1294
|
+
ages.erase("Alice");
|
|
1295
|
+
"""
|
|
1296
|
+
|
|
1297
|
+
def __init__(self, key_type: str = 'dynamic', value_type: str = 'dynamic'):
|
|
1298
|
+
super().__init__()
|
|
1299
|
+
self._key_type = key_type
|
|
1300
|
+
self._value_type = value_type
|
|
1301
|
+
|
|
1302
|
+
def insert(self, key: Any, value: Any) -> 'Map':
|
|
1303
|
+
"""Insert key-value pair (C++ style)"""
|
|
1304
|
+
self[key] = value
|
|
1305
|
+
return self
|
|
1306
|
+
|
|
1307
|
+
def find(self, key: Any) -> Optional[Any]:
|
|
1308
|
+
"""Find value by key, returns None if not found (C++ style)"""
|
|
1309
|
+
return self.get(key, None)
|
|
1310
|
+
|
|
1311
|
+
def erase(self, key: Any) -> bool:
|
|
1312
|
+
"""Erase key-value pair, returns True if existed"""
|
|
1313
|
+
if key in self:
|
|
1314
|
+
del self[key]
|
|
1315
|
+
return True
|
|
1316
|
+
return False
|
|
1317
|
+
|
|
1318
|
+
def contains(self, key: Any) -> bool:
|
|
1319
|
+
"""Check if key exists (C++20 style)"""
|
|
1320
|
+
return key in self
|
|
1321
|
+
|
|
1322
|
+
def count(self, key: Any) -> int:
|
|
1323
|
+
"""Return 1 if key exists, 0 otherwise (C++ style)"""
|
|
1324
|
+
return 1 if key in self else 0
|
|
1325
|
+
|
|
1326
|
+
def size(self) -> int:
|
|
1327
|
+
"""Return map size"""
|
|
1328
|
+
return len(self)
|
|
1329
|
+
|
|
1330
|
+
def empty(self) -> bool:
|
|
1331
|
+
"""Check if map is empty"""
|
|
1332
|
+
return len(self) == 0
|
|
1333
|
+
|
|
1334
|
+
def at(self, key: Any) -> Any:
|
|
1335
|
+
"""Get value at key, raises error if not found (C++ style)"""
|
|
1336
|
+
if key not in self:
|
|
1337
|
+
raise KeyError(f"Key '{key}' not found in map")
|
|
1338
|
+
return self[key]
|
|
1339
|
+
|
|
1340
|
+
def begin(self) -> Optional[tuple]:
|
|
1341
|
+
"""Return first key-value pair"""
|
|
1342
|
+
if len(self) == 0:
|
|
1343
|
+
return None
|
|
1344
|
+
first_key = next(iter(self))
|
|
1345
|
+
return (first_key, self[first_key])
|
|
1346
|
+
|
|
1347
|
+
def end(self) -> Optional[tuple]:
|
|
1348
|
+
"""Return last key-value pair"""
|
|
1349
|
+
if len(self) == 0:
|
|
1350
|
+
return None
|
|
1351
|
+
last_key = list(self.keys())[-1]
|
|
1352
|
+
return (last_key, self[last_key])
|
|
1353
|
+
|
|
1354
|
+
def lower_bound(self, key: Any) -> Optional[Any]:
|
|
1355
|
+
"""Find first key >= given key (for sorted keys)"""
|
|
1356
|
+
sorted_keys = sorted(self.keys())
|
|
1357
|
+
for k in sorted_keys:
|
|
1358
|
+
if k >= key:
|
|
1359
|
+
return k
|
|
1360
|
+
return None
|
|
1361
|
+
|
|
1362
|
+
def upper_bound(self, key: Any) -> Optional[Any]:
|
|
1363
|
+
"""Find first key > given key (for sorted keys)"""
|
|
1364
|
+
sorted_keys = sorted(self.keys())
|
|
1365
|
+
for k in sorted_keys:
|
|
1366
|
+
if k > key:
|
|
1367
|
+
return k
|
|
1368
|
+
return None
|
|
1369
|
+
|
|
1370
|
+
|
|
1371
|
+
def create_map(key_type: str = 'dynamic', value_type: str = 'dynamic') -> Map:
|
|
1372
|
+
"""Create a Map object"""
|
|
1373
|
+
return Map(key_type, value_type)
|
|
1374
|
+
|
|
1375
|
+
|
|
1376
|
+
class CSSLClass:
|
|
1377
|
+
"""Represents a CSSL class definition.
|
|
1378
|
+
|
|
1379
|
+
Stores class name, member variables, methods, and constructor.
|
|
1380
|
+
Used by the runtime to instantiate CSSLInstance objects.
|
|
1381
|
+
"""
|
|
1382
|
+
|
|
1383
|
+
def __init__(self, name: str, members: Dict[str, Any] = None,
|
|
1384
|
+
methods: Dict[str, Any] = None, constructor: Any = None):
|
|
1385
|
+
self.name = name
|
|
1386
|
+
self.members = members or {} # Default member values/types
|
|
1387
|
+
self.methods = methods or {} # Method AST nodes
|
|
1388
|
+
self.constructor = constructor # Constructor AST node
|
|
1389
|
+
|
|
1390
|
+
def __repr__(self):
|
|
1391
|
+
return f"<CSSLClass '{self.name}' with {len(self.methods)} methods>"
|
|
1392
|
+
|
|
1393
|
+
|
|
1394
|
+
class CSSLInstance:
|
|
1395
|
+
"""Represents an instance of a CSSL class.
|
|
1396
|
+
|
|
1397
|
+
Holds instance member values and provides access to class methods.
|
|
1398
|
+
Supports this-> member access pattern.
|
|
1399
|
+
"""
|
|
1400
|
+
|
|
1401
|
+
def __init__(self, class_def: CSSLClass):
|
|
1402
|
+
self._class = class_def
|
|
1403
|
+
self._members: Dict[str, Any] = {}
|
|
1404
|
+
# Initialize members with defaults from class definition
|
|
1405
|
+
for name, default in class_def.members.items():
|
|
1406
|
+
if isinstance(default, dict):
|
|
1407
|
+
# Type declaration with optional default
|
|
1408
|
+
member_type = default.get('type')
|
|
1409
|
+
member_default = default.get('default')
|
|
1410
|
+
|
|
1411
|
+
if member_default is not None:
|
|
1412
|
+
self._members[name] = member_default
|
|
1413
|
+
elif member_type:
|
|
1414
|
+
# Create instance of container types
|
|
1415
|
+
self._members[name] = self._create_default_for_type(member_type)
|
|
1416
|
+
else:
|
|
1417
|
+
self._members[name] = None
|
|
1418
|
+
else:
|
|
1419
|
+
self._members[name] = default
|
|
1420
|
+
|
|
1421
|
+
def _create_default_for_type(self, type_name: str) -> Any:
|
|
1422
|
+
"""Create a default value for a given type name."""
|
|
1423
|
+
# Container types
|
|
1424
|
+
if type_name == 'map':
|
|
1425
|
+
return Map()
|
|
1426
|
+
elif type_name in ('stack',):
|
|
1427
|
+
return Stack()
|
|
1428
|
+
elif type_name in ('vector',):
|
|
1429
|
+
return Vector()
|
|
1430
|
+
elif type_name in ('array',):
|
|
1431
|
+
return Array()
|
|
1432
|
+
elif type_name in ('list',):
|
|
1433
|
+
return List()
|
|
1434
|
+
elif type_name in ('dictionary', 'dict'):
|
|
1435
|
+
return Dictionary()
|
|
1436
|
+
elif type_name == 'datastruct':
|
|
1437
|
+
return DataStruct()
|
|
1438
|
+
elif type_name == 'dataspace':
|
|
1439
|
+
return DataSpace()
|
|
1440
|
+
elif type_name == 'shuffled':
|
|
1441
|
+
return Shuffled()
|
|
1442
|
+
elif type_name == 'iterator':
|
|
1443
|
+
return Iterator()
|
|
1444
|
+
elif type_name == 'combo':
|
|
1445
|
+
return Combo()
|
|
1446
|
+
# Primitive types
|
|
1447
|
+
elif type_name == 'int':
|
|
1448
|
+
return 0
|
|
1449
|
+
elif type_name == 'float':
|
|
1450
|
+
return 0.0
|
|
1451
|
+
elif type_name == 'string':
|
|
1452
|
+
return ""
|
|
1453
|
+
elif type_name == 'bool':
|
|
1454
|
+
return False
|
|
1455
|
+
elif type_name == 'json':
|
|
1456
|
+
return {}
|
|
1457
|
+
return None
|
|
1458
|
+
|
|
1459
|
+
def get_member(self, name: str) -> Any:
|
|
1460
|
+
"""Get member value by name"""
|
|
1461
|
+
if name in self._members:
|
|
1462
|
+
return self._members[name]
|
|
1463
|
+
raise AttributeError(f"'{self._class.name}' has no member '{name}'")
|
|
1464
|
+
|
|
1465
|
+
def set_member(self, name: str, value: Any) -> None:
|
|
1466
|
+
"""Set member value by name"""
|
|
1467
|
+
self._members[name] = value
|
|
1468
|
+
|
|
1469
|
+
def has_member(self, name: str) -> bool:
|
|
1470
|
+
"""Check if member exists"""
|
|
1471
|
+
return name in self._members
|
|
1472
|
+
|
|
1473
|
+
def get_method(self, name: str) -> Any:
|
|
1474
|
+
"""Get method AST node by name"""
|
|
1475
|
+
if name in self._class.methods:
|
|
1476
|
+
return self._class.methods[name]
|
|
1477
|
+
raise AttributeError(f"'{self._class.name}' has no method '{name}'")
|
|
1478
|
+
|
|
1479
|
+
def has_method(self, name: str) -> bool:
|
|
1480
|
+
"""Check if method exists"""
|
|
1481
|
+
return name in self._class.methods
|
|
1482
|
+
|
|
1483
|
+
def __getattr__(self, name: str) -> Any:
|
|
1484
|
+
"""Allow direct attribute access for members"""
|
|
1485
|
+
if name.startswith('_'):
|
|
1486
|
+
raise AttributeError(name)
|
|
1487
|
+
if name in self._members:
|
|
1488
|
+
return self._members[name]
|
|
1489
|
+
raise AttributeError(f"'{self._class.name}' has no member '{name}'")
|
|
1490
|
+
|
|
1491
|
+
def __setattr__(self, name: str, value: Any) -> None:
|
|
1492
|
+
"""Allow direct attribute setting for members"""
|
|
1493
|
+
if name.startswith('_'):
|
|
1494
|
+
object.__setattr__(self, name, value)
|
|
1495
|
+
else:
|
|
1496
|
+
if hasattr(self, '_members'):
|
|
1497
|
+
self._members[name] = value
|
|
1498
|
+
else:
|
|
1499
|
+
object.__setattr__(self, name, value)
|
|
1500
|
+
|
|
1501
|
+
def __repr__(self):
|
|
1502
|
+
return f"<CSSLInstance of '{self._class.name}'>"
|
|
1503
|
+
|
|
1504
|
+
|
|
947
1505
|
__all__ = [
|
|
948
1506
|
'DataStruct', 'Shuffled', 'Iterator', 'Combo', 'DataSpace', 'OpenQuote',
|
|
949
|
-
'OpenFind', 'Parameter', 'Stack', 'Vector', 'Array',
|
|
1507
|
+
'OpenFind', 'Parameter', 'Stack', 'Vector', 'Array', 'List', 'Dictionary', 'Map',
|
|
1508
|
+
'CSSLClass', 'CSSLInstance',
|
|
950
1509
|
'create_datastruct', 'create_shuffled', 'create_iterator',
|
|
951
1510
|
'create_combo', 'create_dataspace', 'create_openquote', 'create_parameter',
|
|
952
|
-
'create_stack', 'create_vector', 'create_array'
|
|
1511
|
+
'create_stack', 'create_vector', 'create_array', 'create_list', 'create_dictionary', 'create_map'
|
|
953
1512
|
]
|