Пример #1
0
            public AltType(LNodeList classAttrs, LNode typeName, LNodeList baseTypes, AltType parentType)
            {
                _classAttrs = classAttrs;
                TypeName    = typeName;
                BaseTypes   = baseTypes;
                ParentType  = parentType;
                //matchCode (TypeName) {
                //	case $stem<$(..a)>, $stem:
                //		_typeNameStem = stem;
                //		_genericArgs = a;
                //  default:
                //		_genericArgs = new WList<LNode>();
                //}
                {                       // Above matchCode expanded:
                    LNode     stem;
                    LNodeList a = default(LNodeList);
                    if (TypeName.CallsMin(CodeSymbols.Of, 1) && (stem = TypeName.Args[0]) != null && (a = new LNodeList(TypeName.Args.Slice(1))).IsEmpty | true || (stem = TypeName) != null)
                    {
                        _typeNameStem = stem;
                        _genericArgs  = a.ToWList();
                    }
                    else
                    {
                        _genericArgs = new WList <LNode>();
                    }
                }
                if (ParentType != null)
                {
                    BaseTypes.Insert(0, ParentType.TypeNameWithoutAttrs);

                    // Search for all 'where' clauses on the ParentType and make sure OUR generic args have them too.
                    bool changed = false;
                    for (int i = 0; i < _genericArgs.Count; i++)
                    {
                        var arg       = _genericArgs[i];
                        var parentArg = ParentType._genericArgs.FirstOrDefault(a => a.IsIdNamed(arg.Name));
                        if (parentArg != null)
                        {
                            var wheres       = new HashSet <LNode>(WhereTypes(arg));
                            int oldCount     = wheres.Count;
                            var parentWheres = WhereTypes(parentArg);
                            foreach (var where in parentWheres)
                            {
                                wheres.Add(where);
                            }
                            if (wheres.Count > oldCount)
                            {
                                arg = arg.WithAttrs(arg.Attrs.SmartWhere(a => !a.Calls(S.WhereClause))
                                                    .Add(LNode.Call(S.WhereClause, LNode.List(wheres))));
                                _genericArgs[i] = arg;
                                changed         = true;
                            }
                        }
                    }
                    if (changed)
                    {
                        TypeName = LNode.Call(CodeSymbols.Of, LNode.List().Add(_typeNameStem).AddRange(_genericArgs)).SetStyle(NodeStyle.Operator);
                    }
                }
                TypeNameWithoutAttrs = TypeName.Select(n => n.WithoutAttrs());
            }