-
-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add suport for FFmpeg 5.1 * Change version Co-authored-by: Ruslan Balanukhin <ruslan@rationale.one>
- Loading branch information
Showing
103 changed files
with
4,200 additions
and
1,326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
FFmpeg.AutoGen.ClangMacroParser.Test/FFmpeg.AutoGen.ClangMacroParser.Test.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
<LangVersion>preview</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" /> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\FFmpeg.AutoGen.ClangMacroParser\FFmpeg.AutoGen.ClangMacroParser.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
using FFmpeg.AutoGen.ClangMacroParser.Expressions; | ||
|
||
namespace FFmpeg.AutoGen.ClangMacroParser.Test | ||
{ | ||
[TestClass] | ||
public class ParserTest | ||
{ | ||
private void CastExpression<T>(IExpression e, params Action<T>[] tests) where T : IExpression | ||
{ | ||
if (e is T) tests.ToList().ForEach(test => test((T)e)); | ||
Assert.IsInstanceOfType(e, typeof(T)); | ||
} | ||
|
||
[TestMethod] | ||
public void String() | ||
{ | ||
CastExpression<ConstantExpression>(Parser.Parse("\"abc\""), x => Assert.AreEqual("abc", x.Value)); | ||
} | ||
|
||
[TestMethod] | ||
public void Char() | ||
{ | ||
CastExpression<ConstantExpression>(Parser.Parse("\'a\'"), x => Assert.AreEqual('a', x.Value)); | ||
} | ||
|
||
[TestMethod] | ||
public void Number() | ||
{ | ||
CastExpression<ConstantExpression>(Parser.Parse("0"), x => Assert.AreEqual(0, x.Value)); // unit | ||
CastExpression<ConstantExpression>(Parser.Parse("0.23"), x => Assert.AreEqual(0.23d, x.Value)); | ||
CastExpression<ConstantExpression>(Parser.Parse("1.23d"), x => Assert.AreEqual(1.23d, x.Value)); | ||
CastExpression<ConstantExpression>(Parser.Parse("1.23f"), x => Assert.AreEqual(1.23f, x.Value)); | ||
CastExpression<ConstantExpression>(Parser.Parse("0.23"), x => Assert.AreEqual(0.23d, x.Value)); | ||
CastExpression<ConstantExpression>(Parser.Parse("1.23d"), x => Assert.AreEqual(1.23d, x.Value)); | ||
CastExpression<ConstantExpression>(Parser.Parse("1.23f"), x => Assert.AreEqual(1.23f, x.Value)); | ||
CastExpression<ConstantExpression>(Parser.Parse("0x0123456789ABCDEF"), x => Assert.AreEqual(0x0123456789ABCDEF, x.Value)); // long | ||
CastExpression<ConstantExpression>(Parser.Parse("0x80000000"), x => Assert.AreEqual(0x80000000, x.Value)); // unit | ||
CastExpression<ConstantExpression>(Parser.Parse("0x8000000000000000ULL"), x => Assert.AreEqual(0x8000000000000000UL, x.Value)); // unit | ||
} | ||
|
||
[TestMethod] | ||
public void Unary() | ||
{ | ||
var e = Parser.Parse(@"(-(1))"); | ||
CastExpression<UnaryExpression>(e, | ||
x => | ||
{ | ||
Assert.AreEqual(OperationType.Subtract, x.OperationType); | ||
Assert.IsInstanceOfType(x.Operand, typeof(ConstantExpression)); | ||
}); | ||
} | ||
|
||
[TestMethod] | ||
public void CastThenBinary() | ||
{ | ||
var e = Parser.Parse(@"((unsigned)(1 - 2))"); | ||
CastExpression<CastExpression>(e, | ||
x => | ||
{ | ||
Assert.AreEqual("unsigned", x.TargetType); | ||
Assert.IsInstanceOfType(x.Operand, typeof(BinaryExpression)); | ||
}); | ||
} | ||
|
||
[TestMethod] | ||
public void BinaryThenCast() | ||
{ | ||
var e = Parser.Parse(@"A | (ulong)(B)"); | ||
CastExpression<BinaryExpression>(e, | ||
x => | ||
{ | ||
Assert.AreEqual(OperationType.Or, x.OperationType); | ||
CastExpression<VariableExpression>(x.Left, y => Assert.AreEqual("A", y.Name)); | ||
CastExpression<CastExpression>(x.Right, | ||
y => | ||
{ | ||
Assert.AreEqual("ulong", y.TargetType); | ||
CastExpression<VariableExpression>(y.Operand, z => Assert.AreEqual("B", z.Name)); | ||
}); | ||
}); | ||
} | ||
|
||
[TestMethod] | ||
public void BinaryPrecedence() | ||
{ | ||
var e = Parser.Parse("1 + 2 * 3"); | ||
CastExpression<BinaryExpression>(e, | ||
x => | ||
{ | ||
Assert.AreEqual(OperationType.Add, x.OperationType); | ||
CastExpression<ConstantExpression>(x.Left, y => Assert.AreEqual(1, y.Value)); | ||
CastExpression<BinaryExpression>(x.Right, | ||
y => | ||
{ | ||
Assert.AreEqual(OperationType.Multiply, y.OperationType); | ||
CastExpression<ConstantExpression>(y.Left, z => Assert.AreEqual(2, z.Value)); | ||
CastExpression<ConstantExpression>(y.Right, z => Assert.AreEqual(3, z.Value)); | ||
}); | ||
}); | ||
} | ||
|
||
[TestMethod] | ||
public void Lamda() | ||
{ | ||
var e = Parser.Parse(@"MKBETAG(a, b, c, d)((d) | ((c) << 8) | ((b) << 16) | ((unsigned)(a) << 24))"); | ||
// todo parsing is incomplete | ||
} | ||
|
||
[TestMethod] | ||
public void Enum() | ||
{ | ||
var e = Parser.Parse("0x1UL << AVChannel.AV_CHAN_FRONT_LEFT"); | ||
// todo finalize test | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using FFmpeg.AutoGen.ClangMacroParser.Tokenization; | ||
|
||
namespace FFmpeg.AutoGen.ClangMacroParser.Test | ||
{ | ||
[TestClass] | ||
public class TokenizerTest | ||
{ | ||
private Token Token(TokenType tokenType, string value) => new(tokenType, value, 0, value.Length); | ||
private static Token[] Tokenize(string expression) => Tokenizer.Tokenize(expression).ToArray(); | ||
|
||
private void AssertAreEqual(Token expected, Token actual) | ||
{ | ||
Assert.AreEqual(expected.TokenType, actual.TokenType); | ||
Assert.AreEqual(expected.Value, actual.Value); | ||
Assert.AreEqual(expected.Length, actual.Length); | ||
} | ||
|
||
[TestMethod] | ||
public void Number() | ||
{ | ||
AssertAreEqual(Token(TokenType.Number, ".23"), Tokenize(@".23").First()); | ||
AssertAreEqual(Token(TokenType.Number, "1.23"), Tokenize(@"1.23").First()); | ||
|
||
AssertAreEqual(Token(TokenType.Number, ".23f"), Tokenize(@".23f").First()); | ||
AssertAreEqual(Token(TokenType.Number, "1.23f"), Tokenize(@"1.23f").First()); | ||
|
||
AssertAreEqual(Token(TokenType.Number, "123"), Tokenize(@"123").First()); | ||
AssertAreEqual(Token(TokenType.Number, "123ull"), Tokenize(@"123ull").First()); | ||
|
||
AssertAreEqual(Token(TokenType.Number, "0xABCDEF"), Tokenize(@"0xABCDEF").First()); | ||
AssertAreEqual(Token(TokenType.Number, "0xABCDEFull"), Tokenize(@"0xABCDEFull").First()); | ||
} | ||
|
||
[TestMethod] | ||
public void Char() | ||
{ | ||
AssertAreEqual(Token(TokenType.Char, "a"), Tokenize(@"'a'").First()); | ||
//AssertAreEqual(Token(TokenType.Char, "\t"), Tokenize(@"'\t'").First()); // todo implement in tokenizer | ||
//AssertAreEqual(Token(TokenType.Char, "\'"), Tokenize(@"'\''").First()); | ||
} | ||
|
||
[TestMethod] | ||
public void String() | ||
{ | ||
AssertAreEqual(Token(TokenType.String, "abc"), Tokenize("\"abc\"").First()); | ||
//AssertAreEqual(Token(TokenType.String, "\t"), Tokenize("\"\t\"").First()); // todo implement in tokenizer | ||
//AssertAreEqual(Token(TokenType.String, "\""), Tokenize("\"\"\"\"").First()); | ||
} | ||
|
||
[TestMethod] | ||
public void MultilineFunction() | ||
{ | ||
var tokens = Tokenize(@"A_B_C(A_B_C, \ | ||
A_B_C)"); | ||
Assert.AreEqual(6, tokens.Length); | ||
AssertAreEqual(Token(TokenType.Identifier, "A_B_C"), tokens[0]); | ||
AssertAreEqual(Token(TokenType.Punctuator, "("), tokens[1]); | ||
AssertAreEqual(Token(TokenType.Identifier, "A_B_C"), tokens[2]); | ||
AssertAreEqual(Token(TokenType.Punctuator, ","), tokens[3]); | ||
AssertAreEqual(Token(TokenType.Identifier, "A_B_C"), tokens[4]); | ||
AssertAreEqual(Token(TokenType.Punctuator, ")"), tokens[5]); | ||
} | ||
|
||
[TestMethod] | ||
public void Expression() | ||
{ | ||
var tokens = Tokenize(@"-1 << 42"); | ||
Assert.AreEqual(4, tokens.Length); | ||
AssertAreEqual(Token(TokenType.Operator, "-"), tokens[0]); | ||
AssertAreEqual(Token(TokenType.Number, "1"), tokens[1]); | ||
AssertAreEqual(Token(TokenType.Operator, "<<"), tokens[2]); | ||
AssertAreEqual(Token(TokenType.Number, "42"), tokens[3]); | ||
} | ||
|
||
[TestMethod] | ||
public void Call() | ||
{ | ||
var tokens = Tokenize(@"TAG('A','B','C')"); | ||
AssertAreEqual(Token(TokenType.Identifier, "TAG"), tokens[0]); | ||
AssertAreEqual(Token(TokenType.Punctuator, "("), tokens[1]); | ||
AssertAreEqual(Token(TokenType.Char, "A"), tokens[2]); | ||
AssertAreEqual(Token(TokenType.Punctuator, ","), tokens[3]); | ||
AssertAreEqual(Token(TokenType.Char, "B"), tokens[4]); | ||
AssertAreEqual(Token(TokenType.Punctuator, ","), tokens[5]); | ||
AssertAreEqual(Token(TokenType.Char, "C"), tokens[6]); | ||
AssertAreEqual(Token(TokenType.Punctuator, ")"), tokens[7]); | ||
} | ||
|
||
[TestMethod] | ||
public void Cast() | ||
{ | ||
var tokens = Tokenize(@"(int)1.0f"); | ||
AssertAreEqual(Token(TokenType.Punctuator, "("), tokens[0]); | ||
AssertAreEqual(Token(TokenType.Keyword, "int"), tokens[1]); | ||
AssertAreEqual(Token(TokenType.Punctuator, ")"), tokens[2]); | ||
AssertAreEqual(Token(TokenType.Number, "1.0f"), tokens[3]); | ||
} | ||
|
||
|
||
[TestMethod] | ||
public void ComplexIdentifier() | ||
{ | ||
var tokens = Tokenize(@"A.B"); | ||
Assert.IsTrue(tokens.Length == 1); | ||
AssertAreEqual(Token(TokenType.Identifier, "A.B"), tokens[0]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Microsoft.VisualStudio.TestTools.UnitTesting; |
16 changes: 16 additions & 0 deletions
16
FFmpeg.AutoGen.ClangMacroParser/Expressions/BinaryExpression.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace FFmpeg.AutoGen.ClangMacroParser.Expressions | ||
{ | ||
public class BinaryExpression : IExpression | ||
{ | ||
public BinaryExpression(IExpression left, OperationType operationType, IExpression right) | ||
{ | ||
Left = left; | ||
OperationType = operationType; | ||
Right = right; | ||
} | ||
|
||
public IExpression Left { get; } | ||
public OperationType OperationType { get; } | ||
public IExpression Right { get; } | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
FFmpeg.AutoGen.ClangMacroParser/Expressions/CallExpression.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace FFmpeg.AutoGen.ClangMacroParser.Expressions | ||
{ | ||
public class CallExpression : IExpression | ||
{ | ||
public CallExpression(string name, IEnumerable<IExpression> args) | ||
{ | ||
Name = name; | ||
Arguments = args.ToArray(); | ||
} | ||
|
||
public IReadOnlyCollection<IExpression> Arguments { get; } | ||
|
||
public string Name { get; } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
FFmpeg.AutoGen.ClangMacroParser/Expressions/CastExpression.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace FFmpeg.AutoGen.ClangMacroParser.Expressions | ||
{ | ||
public class CastExpression : IExpression | ||
{ | ||
public CastExpression(string targetType, IExpression operand) | ||
{ | ||
TargetType = targetType; | ||
Operand = operand; | ||
} | ||
|
||
public string TargetType { get; } | ||
|
||
public IExpression Operand { get; } | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
FFmpeg.AutoGen.ClangMacroParser/Expressions/ConstantExpression.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace FFmpeg.AutoGen.ClangMacroParser.Expressions | ||
{ | ||
public class ConstantExpression : IExpression | ||
{ | ||
public ConstantExpression(object value) => Value = value; | ||
|
||
public object Value { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace FFmpeg.AutoGen.ClangMacroParser.Expressions | ||
{ | ||
public interface IExpression | ||
{ | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
FFmpeg.AutoGen.ClangMacroParser/Expressions/OperationType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace FFmpeg.AutoGen.ClangMacroParser.Expressions | ||
{ | ||
public enum OperationType | ||
{ | ||
Add, | ||
Divide, | ||
Modulo, | ||
Multiply, | ||
Power, | ||
Subtract, | ||
And, | ||
Or, | ||
ExclusiveOr, | ||
LeftShift, | ||
RightShift, | ||
AndAlso, | ||
OrElse, | ||
Equal, | ||
NotEqual, | ||
GreaterThanOrEqual, | ||
GreaterThan, | ||
LessThan, | ||
LessThanOrEqual | ||
} | ||
} |
Oops, something went wrong.