// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Linq;
using EpicGames.Core;
namespace EpicGames.BuildGraph.Expressions
{
///
/// Represents a placeholder for the output from a node, which can be exchanged for the artifacts produced by a node at runtime
///
[BgType(typeof(BgFileSetType))]
public abstract class BgFileSet : BgExpr
{
///
/// Constant empty fileset
///
public static BgFileSet Empty { get; } = new BgFileSetOutputExpr(FileSet.Empty);
///
/// Constructor
///
///
protected BgFileSet(BgExprFlags flags)
: base(flags)
{
}
///
/// Implicit conversion from a regular fileset
///
///
public static implicit operator BgFileSet(FileSet fileSet)
{
return new BgFileSetOutputExpr(fileSet);
}
///
public override BgString ToBgString() => "{FileSet}";
}
///
/// Traits for a
///
class BgFileSetType : BgType
{
///
public override BgFileSet Constant(object value)
{
BgObjectDef obj = (BgObjectDef)value;
BgNodeOutput[] outputs = obj.Deserialize().Flatten().ToArray();
return new BgFileSetInputExpr(outputs);
}
///
public override BgFileSet Wrap(BgExpr expr) => new BgFileSetWrappedExpr(expr);
}
#region Expression classes
class BgFileSetInputExpr : BgFileSet
{
public IReadOnlyList Outputs { get; }
public BgFileSetInputExpr(BgNodeOutput[] outputs)
: base(BgExprFlags.None)
{
Outputs = outputs;
}
public override void Write(BgBytecodeWriter writer)
{
throw new NotImplementedException();
}
}
///
/// /
///
public class BgFileSetOutputExpr : BgFileSet
{
///
///
///
public FileSet Value { get; }
///
///
///
///
public BgFileSetOutputExpr(FileSet value)
: base(BgExprFlags.NotInterned)
{
Value = value;
}
///
public override void Write(BgBytecodeWriter writer)
{
throw new NotImplementedException();
}
}
class BgFileSetFromNodeExpr : BgFileSet
{
public BgNode Node { get; }
public BgFileSetFromNodeExpr(BgNode node)
: base(BgExprFlags.NotInterned)
{
Node = node;
}
public override void Write(BgBytecodeWriter writer)
{
BgObject obj = BgObject.Empty;
obj = obj.Set(x => x.ProducingNode, Node);
writer.WriteExpr(obj);
}
}
class BgFileSetFromNodeOutputExpr : BgFileSet
{
public BgNode Node { get; }
public int OutputIndex { get; }
public BgFileSetFromNodeOutputExpr(BgNode node, int outputIndex)
: base(BgExprFlags.NotInterned)
{
Node = node;
OutputIndex = outputIndex;
}
public override void Write(BgBytecodeWriter writer)
{
BgObject obj = BgObject.Empty;
obj = obj.Set(x => x.ProducingNode, Node);
obj = obj.Set(x => x.OutputIndex, (BgInt)OutputIndex);
writer.WriteExpr(obj);
}
}
class BgFileSetWrappedExpr : BgFileSet
{
public BgExpr Expr { get; }
public BgFileSetWrappedExpr(BgExpr expr)
: base(expr.Flags)
{
Expr = expr;
}
public override void Write(BgBytecodeWriter writer) => Expr.Write(writer);
}
#endregion
}