Code cleanup.
This commit is contained in:
@@ -1,7 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace Cryville.Common.Pdt {
|
||||
/// <summary>
|
||||
/// Indicates that the attributed member is an element list.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>An element list is a <see cref="System.Collections.IDictionary" /> that represents a collection of PDT elements. There must be at most one element list in a class.</para>
|
||||
/// </remarks>
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
||||
public class ElementListAttribute : Attribute { }
|
||||
public class ComponentListAttribute : Attribute { }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the attributed member is a property list.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>A property list is a <see cref="System.Collections.IDictionary" /> that represents a collection of PDT properties. There must be at most one property list in a class.</para>
|
||||
/// </remarks>
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
||||
public class PropertyListAttribute : Attribute { }
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ namespace Cryville.Common.Pdt {
|
||||
/// <summary>
|
||||
/// Whether the value of this expression is constant.
|
||||
/// </summary>
|
||||
/// <remarks>The value of this property is <c>false</c> until it is optimized.</remarks>
|
||||
/// <remarks>The value of this property is <see langword="false" /> until it is optimized.</remarks>
|
||||
public bool IsConstant { get; internal set; }
|
||||
internal bool IsPotentialConstant;
|
||||
internal PdtExpression(LinkedList<PdtInstruction> ins) {
|
||||
|
@@ -34,9 +34,9 @@ namespace Cryville.Common.Pdt {
|
||||
0x0001, 0x0080, 0x0100, 0x0000, 0x0030, 0x0080, 0x0080, 0x0000, 0x0200, 0x0400, 0x0080, 0x0080, 0x0080, 0x0080, 0x0040, 0x0080,
|
||||
0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x0050, 0x1000, 0x1800, 0x0080, 0x0080, 0x0080, 0x0030,
|
||||
0x0080, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030,
|
||||
0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0000, 0x0000, 0x0000, 0x0000, 0x0030,
|
||||
0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0000, 0x0080, 0x0000, 0x0080, 0x0030,
|
||||
0x0000, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030,
|
||||
0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x1000, 0x0080, 0x1000, 0x0000, 0x0000,
|
||||
0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x0030, 0x1000, 0x0080, 0x1000, 0x0080, 0x0000,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -57,40 +57,90 @@ namespace Cryville.Common.Pdt {
|
||||
return (T)new PdtInterpreter(src, typeof(T), binder).Interpret();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The source string.
|
||||
/// </summary>
|
||||
public string Source { get; private set; }
|
||||
readonly Type _type;
|
||||
readonly Binder _binder;
|
||||
/// <summary>
|
||||
/// The current position in the string being parsed by the interpreter.
|
||||
/// </summary>
|
||||
public int Position { get; private set; }
|
||||
#pragma warning disable IDE1006
|
||||
/// <summary>
|
||||
/// The character at the current position.
|
||||
/// </summary>
|
||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||
protected char cc { get { return Source[Position]; } }
|
||||
/// <summary>
|
||||
/// The category of the character.
|
||||
/// </summary>
|
||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||
protected int ct { get { return cm[cc]; } }
|
||||
protected string tokenb(int flag) { // Token Whitelist
|
||||
/// <summary>
|
||||
/// Reads a token until a character of type <paramref name="flag" /> is met.
|
||||
/// </summary>
|
||||
/// <param name="flag">The type filter.</param>
|
||||
/// <returns>A token from the current position (inclusive) to the next character of type <paramref name="flag" /> (exclusive).</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">No character of type <paramref name="flag" /> is met.</exception>
|
||||
protected string tokenb(int flag) {
|
||||
int sp = Position;
|
||||
while ((ct & flag) == 0) Position++;
|
||||
return Source.Substring(sp, Position - sp);
|
||||
}
|
||||
protected string tokenw(int flag) { // Token Whitelist
|
||||
/// <summary>
|
||||
/// Reads a token until a character that is not of type <paramref name="flag" /> is met.
|
||||
/// </summary>
|
||||
/// <param name="flag">The type filter.</param>
|
||||
/// <returns>A token from the current position (inclusive) to the next character that is not of type <paramref name="flag" /> (exclusive).</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">No character that is not of type <paramref name="flag" /> is met.</exception>
|
||||
protected string tokenw(int flag) {
|
||||
int sp = Position;
|
||||
while ((ct & flag) != 0) Position++;
|
||||
return Source.Substring(sp, Position - sp);
|
||||
}
|
||||
/// <summary>
|
||||
/// Skips over whitespaces.
|
||||
/// </summary>
|
||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||
protected void ws() {
|
||||
while ((ct & 0x0001) != 0) Position++;
|
||||
}
|
||||
#pragma warning restore IDE1006
|
||||
|
||||
/// <summary>
|
||||
/// Reads the current character and increments the position.
|
||||
/// </summary>
|
||||
/// <returns>The current character.</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||
protected char GetChar() {
|
||||
char r = cc;
|
||||
Position++;
|
||||
return r;
|
||||
}
|
||||
/// <summary>
|
||||
/// Reads an identifier.
|
||||
/// </summary>
|
||||
/// <returns>An identifier.</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||
protected string GetIdentifier() {
|
||||
if ((ct & 0x0020) == 0) return "";
|
||||
return tokenw(0x0010);
|
||||
}
|
||||
/// <summary>
|
||||
/// Reads a number.
|
||||
/// </summary>
|
||||
/// <returns>A number.</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||
protected string GetNumber() {
|
||||
return tokenw(0x0040);
|
||||
}
|
||||
/// <summary>
|
||||
/// Reads a string.
|
||||
/// </summary>
|
||||
/// <returns>A string.</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||
protected string GetString() {
|
||||
int sp = Position;
|
||||
do {
|
||||
@@ -100,6 +150,11 @@ namespace Cryville.Common.Pdt {
|
||||
Position++;
|
||||
return Regex.Replace(Source.Substring(sp + 1, Position - sp - 2), @"\\(.)", "$1");
|
||||
}
|
||||
/// <summary>
|
||||
/// Reads an expression.
|
||||
/// </summary>
|
||||
/// <returns>An expression.</returns>
|
||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||
protected PdtExpression GetExp() {
|
||||
var ins = new LinkedList<PdtInstruction>();
|
||||
int _;
|
||||
@@ -219,6 +274,8 @@ namespace Cryville.Common.Pdt {
|
||||
if (prop == null) throw new MissingMemberException(string.Format("The property \"{0}\" is not found", pkey));
|
||||
var ptype = ReflectionHelper.GetMemberType(prop);
|
||||
if (flag) {
|
||||
if (!typeof(IDictionary).IsAssignableFrom(ptype))
|
||||
throw new InvalidOperationException("Internal error: Property list is not a dictionary");
|
||||
var ktype = ptype.GetGenericArguments()[0];
|
||||
var vtype = ptype.GetGenericArguments()[1];
|
||||
object key = _binder.ChangeType(pkey, ktype, null);
|
||||
@@ -238,6 +295,10 @@ namespace Cryville.Common.Pdt {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Interprets a key from the current position.
|
||||
/// </summary>
|
||||
/// <returns>The interpreted key.</returns>
|
||||
protected virtual object InterpretKey(Type type) {
|
||||
return tokenb(0x1000).Trim();
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ namespace Cryville.Common.Pdt {
|
||||
/// <summary>
|
||||
/// The count of the operands loaded.
|
||||
/// </summary>
|
||||
protected int LoadedOperandCount { get { return ParamCount - _loadindex; } }
|
||||
protected int LoadedOperandCount { get { return _pc - _loadindex; } }
|
||||
/// <summary>
|
||||
/// Gets the operand at the specified index.
|
||||
/// </summary>
|
||||
@@ -24,20 +24,20 @@ namespace Cryville.Common.Pdt {
|
||||
int i = index + _loadindex;
|
||||
return _operands[i];
|
||||
}
|
||||
internal int ParamCount { get; private set; }
|
||||
readonly int _pc;
|
||||
/// <summary>
|
||||
/// Creates an instance of the <see cref="PdtOperator" /> class.
|
||||
/// </summary>
|
||||
/// <param name="pc">The suggested parameter count.</param>
|
||||
protected PdtOperator(int pc) {
|
||||
ParamCount = pc;
|
||||
_pc = pc;
|
||||
_operands = new PdtVariableMemory[pc];
|
||||
}
|
||||
PdtEvaluatorBase _etor;
|
||||
bool _rfreq = true;
|
||||
internal void Begin(PdtEvaluatorBase etor) {
|
||||
_etor = etor;
|
||||
_loadindex = ParamCount;
|
||||
_loadindex = _pc;
|
||||
}
|
||||
internal void LoadOperand(PdtVariableMemory mem) {
|
||||
if (_loadindex == 0) return;
|
||||
@@ -55,6 +55,9 @@ namespace Cryville.Common.Pdt {
|
||||
/// <summary>
|
||||
/// Executes the operator.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>When overridden, this method reads operands by calling <see cref="GetOperand(int)" />, and writes the result to the frame obtained by calling <see cref="GetReturnFrame(int, int)" />.</para>
|
||||
/// </remarks>
|
||||
protected abstract void Execute();
|
||||
/// <summary>
|
||||
/// Gets a return frame.
|
||||
|
@@ -43,7 +43,9 @@ namespace Cryville.Common.Pdt {
|
||||
/// <param name="dest">The destination buffer.</param>
|
||||
/// <param name="destOffset">The offset on the destination buffer to start copying to.</param>
|
||||
/// <param name="length">The length to copy.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="length" /> is greater than the length of the span.</exception>
|
||||
public void CopyTo(byte* dest, int destOffset, int length) {
|
||||
if (length > Length) throw new ArgumentOutOfRangeException("length");
|
||||
for (int i = 0; i < length; i++)
|
||||
dest[destOffset + i] = _ptr[i];
|
||||
}
|
||||
|
@@ -45,7 +45,7 @@ namespace Cryville.Common.Unity.UI {
|
||||
}
|
||||
|
||||
static MethodInfo _methodCreateFontAsset;
|
||||
static object[] _paramsCreateFontAsset = new object[] { null, null, 90, 9, GlyphRenderMode.SDFAA, 1024, 1024, Type.Missing, Type.Missing };
|
||||
static readonly object[] _paramsCreateFontAsset = new object[] { null, null, 90, 9, GlyphRenderMode.SDFAA, 1024, 1024, Type.Missing, Type.Missing };
|
||||
static FontAsset CreateFontAsset(string path, int index) {
|
||||
if (_methodCreateFontAsset == null) {
|
||||
_methodCreateFontAsset = typeof(FontAsset).GetMethod(
|
||||
|
@@ -152,7 +152,7 @@ namespace Cryville.Crtr.Components {
|
||||
List<Vector3> verts;
|
||||
List<Vector2> uvs;
|
||||
List<int> trih = null, trib = null, trit = null;
|
||||
static List<int> _emptyTris = new List<int>();
|
||||
static readonly List<int> _emptyTris = new List<int>();
|
||||
|
||||
public override void Seal() {
|
||||
if (vertCount <= 1 || sumLength == 0) return;
|
||||
|
Reference in New Issue
Block a user