public ITypeHLSL MakeArrayType(
     ITypeHLSL elementType,
     EmitValHLSL elementCount)
 {
     if (elementType is RealTypeHLSL)
     {
         return new ArrayTypeHLSL(
             (RealTypeHLSL)elementType,
             elementCount);
     }
     else
     {
         return new PseudoArrayTypeHLSL(
             MakePseudoArrayElemType(elementType, elementCount),
             elementCount);
     }
 }
 public IEnumerable<string> DeclareBase(
     EmitValHLSL val,
     string prefix,
     string semantic,
     string suffix)
 {
     return DeclareBaseImpl(
         (dynamic) val,
         prefix,
         semantic,
         suffix);
 }
 public ArrayTypeBaseHLSL(
     RealTypeHLSL elementType,
     EmitValHLSL elementCount)
 {
     _elementType = elementType;
     _elementCount = elementCount;
 }
 // Bind an attribute to a given value
 public void BindAttr(
     MidAttributeWrapperDecl wrapper,
     EmitValHLSL val)
 {
     BindAttr(wrapper.Attribute, val);
 }
 public void DeclareAndInitLocal(
     EmitValHLSL local,
     EmitValHLSL init,
     Span span)
 {
     DeclareAndInitLocalImpl(
         (dynamic)local,
         (dynamic)init,
         span);
 }
 public PseudoArrayTypeHLSL(
     ITypeHLSL elementType,
     EmitValHLSL elementCount)
 {
     _elementType = elementType;
     _elementCount = elementCount;
 }
 public override EmitValHLSL CreateVal(string name)
 {
     int fieldCount = GetFieldCount();
     EmitValHLSL[] fieldVals = new EmitValHLSL[fieldCount];
     for (int ff = 0; ff < fieldCount; ++ff)
     {
         fieldVals[ff] = GetFieldType(ff).CreateVal(name + GetFieldName(ff));
     }
     return new TupleValHLSL(this, fieldVals);
 }
        // Declare function parameters
        private void DeclareParam(
            EmitValHLSL val,
            string prefix,
            string semantic,
            ref bool first,
            Span span)
        {
            var decls = DeclareBase(
                val,
                prefix,
                semantic,
                "");

            foreach (var d in decls)
            {
                if (!first)
                    span.WriteLine(",");
                first = false;
                span.Write(d);
            }
        }
 private EmitValHLSL GetField(
     EmitValHLSL objVal,
     ITypeHLSL fieldRep,
     string fieldName,
     int fieldIndex,
     Span span)
 {
     return GetFieldImpl(
         (dynamic)objVal,
         (dynamic)fieldRep,
         fieldName,
         fieldIndex,
         span);
 }
        private EmitValHLSL DeclareAndInitRecord(
            Span span,
            MidElementDecl record,
            EmitValHLSL destVar)
        {
            var recordVal = EvaluateRecordAttrs(span, record);

            DeclareAndInitLocal(
                destVar,
                recordVal,
                span);

            return destVar;
        }
 private ITypeHLSL DeclareConnectorFields(
     ITypeHLSL rep,
     string name,
     string semantic,
     Span span,
     EmitValHLSL[] arrayDims = null)
 {
     DeclareFields(
         rep,
         span,
         name,
         semantic: semantic);
     return rep;
 }
 private void AssignImpl(
     EmitValHLSL dest,
     VoidValHLSL src,
     Span span)
 {
 }
 private void AddArgs(
     EmitValHLSL val,
     ref bool first,
     Span span)
 {
     AddArgsImpl(
         (dynamic)val,
         ref first,
         span);
 }
 public ArrayTypeHLSL(
     RealTypeHLSL elementType,
     EmitValHLSL elementCount)
     : base(elementType, elementCount)
 {
 }
 public override void Emit(
     EmitValHLSL val,
     Span span)
 {
     _context.Assign(
         _resultVar,
         val,
         span);
     span.WriteLine("return;");
 }
 private ITypeHLSL MakePseudoArrayElemType(
     ITypeHLSL type,
     EmitValHLSL count)
 {
     return MakePseudoArrayElemTypeImpl(
         (dynamic)type,
         count);
 }
 public PseudoArrayElemTypeHLSL(
     RealTypeHLSL elementType,
     EmitValHLSL elementCount)
     : base(elementType, elementCount)
 {
 }
 private ITypeHLSL MakePseudoArrayElemTypeImpl(
     RealTypeHLSL type,
     EmitValHLSL count)
 {
     return new PseudoArrayElemTypeHLSL(type, count);
 }
 public PseudoArrayValHLSL(
     PseudoArrayTypeHLSL type,
     EmitValHLSL innerVal)
     : base(type)
 {
     _innerVal = innerVal;
 }
 private ITypeHLSL MakePseudoArrayElemTypeImpl(
     TupleTypeHLSL type,
     EmitValHLSL count )
 {
     int fieldCount = type.GetFieldCount();
     TupleTypeHLSL result = new TupleTypeHLSL(type.Name);
     for (int ff = 0; ff < fieldCount; ++ff)
     {
         result.AddField(
             type.GetFieldName(ff),
             MakePseudoArrayElemType(
                 type.GetFieldType(ff),
                 count));
     }
     return result;
 }
 public void Assign(
     EmitValHLSL dst,
     EmitValHLSL src,
     Span span)
 {
     AssignImpl(
         (dynamic)dst,
         (dynamic)src,
         span);
 }
 private ITypeHLSL MakePseudoArrayElemTypeImpl(
     PseudoArrayTypeHLSL type,
     EmitValHLSL count)
 {
     return new PseudoArrayTypeHLSL(
         MakePseudoArrayElemType(
             type.ElementType,
             count),
         type.ElementCount);
 }
 public void BindAttr(
     MidAttributeDecl attr,
     EmitValHLSL val)
 {
     _attrVals[attr] = val;
 }
 public BreakLabel(
     MidLabel midLabel,
     EmitContextHLSL context,
     EmitValHLSL resultVar)
 {
     _midLabel = midLabel;
     _context = context;
     _resultVar = resultVar;
 }
        public void DeclareAndInitLocalImpl(
            TupleValHLSL local,
            EmitValHLSL init,
            Span span)
        {
            int fieldCount = local.GetFieldCount();

            var aggType = local.AggType;

            for (int ii = 0; ii < fieldCount; ++ii)
            {
                var fieldInit = GetField(
                    init,
                    aggType.GetFieldType(ii),
                    aggType.GetFieldName(ii),
                    ii,
                    span);

                DeclareAndInitLocal(
                    local.GetFieldVal(ii),
                    fieldInit,
                    span);
            }
        }
 public abstract void Emit(
     EmitValHLSL val,
     Span span);
 public void DeclareLocal(
     EmitValHLSL val,
     Span span)
 {
     DeclareLocalImpl(
         (dynamic)val,
         span);
 }
 public ReturnLabel(
     EmitContextHLSL context,
     EmitValHLSL resultVar)
 {
     _context = context;
     _resultVar = resultVar;
 }
        //
        public EmitValHLSL FetchAttr(
            EmitValHLSL objVal,
            MidAttributeDecl attr,
            Span span)
        {
            var attrType = EmitType(attr.Type);
            var attrName = MapName(attr);

            int attrIndex = 0;
            foreach (var a in attr.Element.Outputs)
            {
                if (a == attr)
                    break;
                attrIndex++;
            }

            var objType = (IAggTypeHLSL)objVal.Type;

            return GetField(
                objVal,
                objType.GetFieldType(attrIndex),
                attrName,
                attrIndex,
                span);
        }
        public EmitValHLSL InitRecord(
            Span span,
            MidElementDecl record,
            EmitValHLSL destVar)
        {
            var recordVal = EvaluateRecordAttrs(span, record);

            Assign(
                destVar,
                recordVal,
                span);

            return destVar;
        }