2023-03-04 14:43:08 +01:00
|
|
|
|
using Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast;
|
|
|
|
|
using System;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Diagnostics.Demangler
|
|
|
|
|
{
|
|
|
|
|
class Demangler
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private static readonly string Base36 = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
|
|
|
private List<BaseNode> _substitutionList = new List<BaseNode>();
|
|
|
|
|
private List<BaseNode> _templateParamList = new List<BaseNode>();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private List<ForwardTemplateReference> _forwardTemplateReferenceList = new List<ForwardTemplateReference>();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
public string Mangled { get; private set; }
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private int _position;
|
|
|
|
|
private int _length;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private bool _canForwardTemplateReference;
|
|
|
|
|
private bool _canParseTemplateArgs;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
public Demangler(string mangled)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
Mangled = mangled;
|
|
|
|
|
_position = 0;
|
|
|
|
|
_length = mangled.Length;
|
|
|
|
|
_canParseTemplateArgs = true;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private bool ConsumeIf(string toConsume)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2023-01-18 23:25:16 +01:00
|
|
|
|
var mangledPart = Mangled.AsSpan(_position);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2023-01-18 23:25:16 +01:00
|
|
|
|
if (mangledPart.StartsWith(toConsume.AsSpan()))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += toConsume.Length;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 23:25:16 +01:00
|
|
|
|
private ReadOnlySpan<char> PeekString(int offset = 0, int length = 1)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (_position + offset >= length)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 23:25:16 +01:00
|
|
|
|
return Mangled.AsSpan(_position + offset, length);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private char Peek(int offset = 0)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (_position + offset >= _length)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return '\0';
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return Mangled[_position + offset];
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private char Consume()
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (_position < _length)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return Mangled[_position++];
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return '\0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int Count()
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return _length - _position;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private static int FromBase36(string encoded)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
char[] reversedEncoded = encoded.ToLower().ToCharArray().Reverse().ToArray();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
int result = 0;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
for (int i = 0; i < reversedEncoded.Length; i++)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
int value = Base36.IndexOf(reversedEncoded[i]);
|
|
|
|
|
if (value == -1)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result += value * (int)Math.Pow(36, i);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return result;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int ParseSeqId()
|
|
|
|
|
{
|
2023-01-18 23:25:16 +01:00
|
|
|
|
ReadOnlySpan<char> part = Mangled.AsSpan(_position);
|
|
|
|
|
int seqIdLen = 0;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
for (; seqIdLen < part.Length; seqIdLen++)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (!char.IsLetterOrDigit(part[seqIdLen]))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += seqIdLen;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2023-01-18 23:25:16 +01:00
|
|
|
|
return FromBase36(new string(part[..seqIdLen]));
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <substitution> ::= S <seq-id> _
|
|
|
|
|
// ::= S_
|
|
|
|
|
// ::= St # std::
|
|
|
|
|
// ::= Sa # std::allocator
|
|
|
|
|
// ::= Sb # std::basic_string
|
|
|
|
|
// ::= Ss # std::basic_string<char, std::char_traits<char>, std::allocator<char> >
|
|
|
|
|
// ::= Si # std::basic_istream<char, std::char_traits<char> >
|
|
|
|
|
// ::= So # std::basic_ostream<char, std::char_traits<char> >
|
|
|
|
|
// ::= Sd # std::basic_iostream<char, std::char_traits<char> >
|
|
|
|
|
private BaseNode ParseSubstitution()
|
|
|
|
|
{
|
|
|
|
|
if (!ConsumeIf("S"))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
char substitutionSecondChar = Peek();
|
|
|
|
|
if (char.IsLower(substitutionSecondChar))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
switch (substitutionSecondChar)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
case 'a':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new SpecialSubstitution(SpecialSubstitution.SpecialType.Allocator);
|
|
|
|
|
case 'b':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new SpecialSubstitution(SpecialSubstitution.SpecialType.BasicString);
|
|
|
|
|
case 's':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new SpecialSubstitution(SpecialSubstitution.SpecialType.String);
|
|
|
|
|
case 'i':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new SpecialSubstitution(SpecialSubstitution.SpecialType.IStream);
|
|
|
|
|
case 'o':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new SpecialSubstitution(SpecialSubstitution.SpecialType.OStream);
|
|
|
|
|
case 'd':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new SpecialSubstitution(SpecialSubstitution.SpecialType.IOStream);
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ::= S_
|
|
|
|
|
if (ConsumeIf("_"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (_substitutionList.Count != 0)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return _substitutionList[0];
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ::= S <seq-id> _
|
2018-12-06 12:16:24 +01:00
|
|
|
|
int seqId = ParseSeqId();
|
|
|
|
|
if (seqId < 0)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
seqId++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (!ConsumeIf("_") || seqId >= _substitutionList.Count)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return _substitutionList[seqId];
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOTE: thoses data aren't used in the output
|
|
|
|
|
// <call-offset> ::= h <nv-offset> _
|
|
|
|
|
// ::= v <v-offset> _
|
|
|
|
|
// <nv-offset> ::= <offset number>
|
|
|
|
|
// # non-virtual base override
|
|
|
|
|
// <v-offset> ::= <offset number> _ <virtual offset number>
|
|
|
|
|
// # virtual base override, with vcall offset
|
|
|
|
|
private bool ParseCallOffset()
|
|
|
|
|
{
|
|
|
|
|
if (ConsumeIf("h"))
|
|
|
|
|
{
|
|
|
|
|
return ParseNumber(true).Length == 0 || !ConsumeIf("_");
|
|
|
|
|
}
|
|
|
|
|
else if (ConsumeIf("v"))
|
|
|
|
|
{
|
|
|
|
|
return ParseNumber(true).Length == 0 || !ConsumeIf("_") || ParseNumber(true).Length == 0 || !ConsumeIf("_");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// <class-enum-type> ::= <name> # non-dependent type name, dependent type name, or dependent typename-specifier
|
|
|
|
|
// ::= Ts <name> # dependent elaborated type specifier using 'struct' or 'class'
|
|
|
|
|
// ::= Tu <name> # dependent elaborated type specifier using 'union'
|
|
|
|
|
// ::= Te <name> # dependent elaborated type specifier using 'enum'
|
|
|
|
|
private BaseNode ParseClassEnumType()
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
string elaboratedType = null;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
|
|
|
|
if (ConsumeIf("Ts"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
elaboratedType = "struct";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
else if (ConsumeIf("Tu"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
elaboratedType = "union";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
else if (ConsumeIf("Te"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
elaboratedType = "enum";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode name = ParseName();
|
|
|
|
|
if (name == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (elaboratedType == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return name;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new ElaboratedType(elaboratedType, name);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <function-type> ::= [<CV-qualifiers>] [<exception-spec>] [Dx] F [Y] <bare-function-type> [<ref-qualifier>] E
|
|
|
|
|
// <bare-function-type> ::= <signature type>+
|
|
|
|
|
// # types are possible return type, then parameter types
|
|
|
|
|
// <exception-spec> ::= Do # non-throwing exception-specification (e.g., noexcept, throw())
|
|
|
|
|
// ::= DO <expression> E # computed (instantiation-dependent) noexcept
|
|
|
|
|
// ::= Dw <type>+ E # dynamic exception specification with instantiation-dependent types
|
|
|
|
|
private BaseNode ParseFunctionType()
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
Cv cvQualifiers = ParseCvQualifiers();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode exceptionSpec = null;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
|
|
|
|
if (ConsumeIf("Do"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
exceptionSpec = new NameType("noexcept");
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
else if (ConsumeIf("DO"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode expression = ParseExpression();
|
|
|
|
|
if (expression == null || !ConsumeIf("E"))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
exceptionSpec = new NoexceptSpec(expression);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
else if (ConsumeIf("Dw"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
List<BaseNode> types = new List<BaseNode>();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
|
|
|
|
while (!ConsumeIf("E"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode type = ParseType();
|
|
|
|
|
if (type == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
types.Add(type);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
exceptionSpec = new DynamicExceptionSpec(new NodeArray(types));
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We don't need the transaction
|
|
|
|
|
ConsumeIf("Dx");
|
|
|
|
|
|
|
|
|
|
if (!ConsumeIf("F"))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// extern "C"
|
|
|
|
|
ConsumeIf("Y");
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode returnType = ParseType();
|
|
|
|
|
if (returnType == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
Reference referenceQualifier = Reference.None;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
List<BaseNode> Params = new List<BaseNode>();
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if (ConsumeIf("E"))
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ConsumeIf("v"))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ConsumeIf("RE"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
referenceQualifier = Reference.LValue;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (ConsumeIf("OE"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
referenceQualifier = Reference.RValue;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode type = ParseType();
|
|
|
|
|
if (type == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
Params.Add(type);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new FunctionType(returnType, new NodeArray(Params), new CvType(cvQualifiers, null), new SimpleReferenceType(referenceQualifier, null), exceptionSpec);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <array-type> ::= A <positive dimension number> _ <element type>
|
|
|
|
|
// ::= A [<dimension expression>] _ <element type>
|
|
|
|
|
private BaseNode ParseArrayType()
|
|
|
|
|
{
|
|
|
|
|
if (!ConsumeIf("A"))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode elementType;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
if (char.IsDigit(Peek()))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
string dimension = ParseNumber();
|
|
|
|
|
if (dimension.Length == 0 || !ConsumeIf("_"))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
elementType = ParseType();
|
|
|
|
|
if (elementType == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new ArrayType(elementType, dimension);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ConsumeIf("_"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode dimensionExpression = ParseExpression();
|
|
|
|
|
if (dimensionExpression == null || !ConsumeIf("_"))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
elementType = ParseType();
|
|
|
|
|
if (elementType == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new ArrayType(elementType, dimensionExpression);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
elementType = ParseType();
|
|
|
|
|
if (elementType == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new ArrayType(elementType);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <type> ::= <builtin-type>
|
|
|
|
|
// ::= <qualified-type> (PARTIAL)
|
|
|
|
|
// ::= <function-type>
|
|
|
|
|
// ::= <class-enum-type>
|
|
|
|
|
// ::= <array-type> (TODO)
|
|
|
|
|
// ::= <pointer-to-member-type> (TODO)
|
|
|
|
|
// ::= <template-param>
|
|
|
|
|
// ::= <template-template-param> <template-args>
|
|
|
|
|
// ::= <decltype>
|
|
|
|
|
// ::= P <type> # pointer
|
|
|
|
|
// ::= R <type> # l-value reference
|
|
|
|
|
// ::= O <type> # r-value reference (C++11)
|
|
|
|
|
// ::= C <type> # complex pair (C99)
|
|
|
|
|
// ::= G <type> # imaginary (C99)
|
|
|
|
|
// ::= <substitution> # See Compression below
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private BaseNode ParseType(NameParserContext context = null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
// Temporary context
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (context == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
context = new NameParserContext();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode result = null;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
switch (Peek())
|
|
|
|
|
{
|
|
|
|
|
case 'r':
|
|
|
|
|
case 'V':
|
|
|
|
|
case 'K':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
int typePos = 0;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (Peek(typePos) == 'r')
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
typePos++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (Peek(typePos) == 'V')
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
typePos++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (Peek(typePos) == 'K')
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
typePos++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (Peek(typePos) == 'F' || (Peek(typePos) == 'D' && (Peek(typePos + 1) == 'o' || Peek(typePos + 1) == 'O' || Peek(typePos + 1) == 'w' || Peek(typePos + 1) == 'x')))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = ParseFunctionType();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
Cv cv = ParseCvQualifiers();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = ParseType(context);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (result == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = new CvType(cv, result);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case 'U':
|
|
|
|
|
// TODO: <extended-qualifier>
|
|
|
|
|
return null;
|
|
|
|
|
case 'v':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("void");
|
|
|
|
|
case 'w':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("wchar_t");
|
|
|
|
|
case 'b':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("bool");
|
|
|
|
|
case 'c':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("char");
|
|
|
|
|
case 'a':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("signed char");
|
|
|
|
|
case 'h':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("unsigned char");
|
|
|
|
|
case 's':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("short");
|
|
|
|
|
case 't':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("unsigned short");
|
|
|
|
|
case 'i':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("int");
|
|
|
|
|
case 'j':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("unsigned int");
|
|
|
|
|
case 'l':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("long");
|
|
|
|
|
case 'm':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("unsigned long");
|
|
|
|
|
case 'x':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("long long");
|
|
|
|
|
case 'y':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("unsigned long long");
|
|
|
|
|
case 'n':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("__int128");
|
|
|
|
|
case 'o':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("unsigned __int128");
|
|
|
|
|
case 'f':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("float");
|
|
|
|
|
case 'd':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("double");
|
|
|
|
|
case 'e':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("long double");
|
|
|
|
|
case 'g':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("__float128");
|
|
|
|
|
case 'z':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("...");
|
|
|
|
|
case 'u':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseSourceName();
|
|
|
|
|
case 'D':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'd':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("decimal64");
|
|
|
|
|
case 'e':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("decimal128");
|
|
|
|
|
case 'f':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("decimal32");
|
|
|
|
|
case 'h':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
// FIXME: GNU c++flit returns this but that is not what is supposed to be returned.
|
|
|
|
|
return new NameType("half");
|
2019-07-02 04:39:22 +02:00
|
|
|
|
// return new NameType("decimal16");
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 'i':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("char32_t");
|
|
|
|
|
case 's':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("char16_t");
|
|
|
|
|
case 'a':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("decltype(auto)");
|
|
|
|
|
case 'n':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
// FIXME: GNU c++flit returns this but that is not what is supposed to be returned.
|
|
|
|
|
return new NameType("decltype(nullptr)");
|
2019-07-02 04:39:22 +02:00
|
|
|
|
// return new NameType("std::nullptr_t");
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 't':
|
|
|
|
|
case 'T':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
result = ParseDecltype();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case 'o':
|
|
|
|
|
case 'O':
|
|
|
|
|
case 'w':
|
|
|
|
|
case 'x':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = ParseFunctionType();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'F':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = ParseFunctionType();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case 'A':
|
|
|
|
|
return ParseArrayType();
|
|
|
|
|
case 'M':
|
|
|
|
|
// TODO: <pointer-to-member-type>
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return null;
|
|
|
|
|
case 'T':
|
|
|
|
|
// might just be a class enum type
|
|
|
|
|
if (Peek(1) == 's' || Peek(1) == 'u' || Peek(1) == 'e')
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = ParseClassEnumType();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = ParseTemplateParam();
|
|
|
|
|
if (result == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (_canParseTemplateArgs && Peek() == 'I')
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode templateArguments = ParseTemplateArguments();
|
|
|
|
|
if (templateArguments == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = new NameTypeWithTemplateArguments(result, templateArguments);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'P':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
|
|
|
|
result = ParseType(context);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (result == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = new PointerType(result);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case 'R':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
|
|
|
|
result = ParseType(context);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (result == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = new ReferenceType("&", result);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case 'O':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
|
|
|
|
result = ParseType(context);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (result == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = new ReferenceType("&&", result);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case 'C':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
|
|
|
|
result = ParseType(context);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (result == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = new PostfixQualifiedType(" complex", result);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case 'G':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
|
|
|
|
result = ParseType(context);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (result == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = new PostfixQualifiedType(" imaginary", result);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case 'S':
|
|
|
|
|
if (Peek(1) != 't')
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode substitution = ParseSubstitution();
|
|
|
|
|
if (substitution == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (_canParseTemplateArgs && Peek() == 'I')
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode templateArgument = ParseTemplateArgument();
|
|
|
|
|
if (templateArgument == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = new NameTypeWithTemplateArguments(substitution, templateArgument);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return substitution;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = ParseClassEnumType();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = ParseClassEnumType();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (result != null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_substitutionList.Add(result);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return result;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <special-name> ::= TV <type> # virtual table
|
|
|
|
|
// ::= TT <type> # VTT structure (construction vtable index)
|
|
|
|
|
// ::= TI <type> # typeinfo structure
|
|
|
|
|
// ::= TS <type> # typeinfo name (null-terminated byte string)
|
|
|
|
|
// ::= Tc <call-offset> <call-offset> <base encoding>
|
|
|
|
|
// ::= TW <object name> # Thread-local wrapper
|
|
|
|
|
// ::= TH <object name> # Thread-local initialization
|
|
|
|
|
// ::= T <call-offset> <base encoding>
|
|
|
|
|
// # base is the nominal target function of thunk
|
|
|
|
|
// ::= GV <object name> # Guard variable for one-time initialization
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private BaseNode ParseSpecialName(NameParserContext context = null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
if (Peek() != 'T')
|
|
|
|
|
{
|
|
|
|
|
if (ConsumeIf("GV"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode name = ParseName();
|
|
|
|
|
if (name == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new SpecialName("guard variable for ", name);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode node;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
// ::= TV <type> # virtual table
|
|
|
|
|
case 'V':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
node = ParseType(context);
|
|
|
|
|
if (node == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new SpecialName("vtable for ", node);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
// ::= TT <type> # VTT structure (construction vtable index)
|
|
|
|
|
case 'T':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
node = ParseType(context);
|
|
|
|
|
if (node == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new SpecialName("VTT for ", node);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
// ::= TI <type> # typeinfo structure
|
|
|
|
|
case 'I':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
node = ParseType(context);
|
|
|
|
|
if (node == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new SpecialName("typeinfo for ", node);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
// ::= TS <type> # typeinfo name (null-terminated byte string)
|
|
|
|
|
case 'S':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
node = ParseType(context);
|
|
|
|
|
if (node == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new SpecialName("typeinfo name for ", node);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
// ::= Tc <call-offset> <call-offset> <base encoding>
|
|
|
|
|
case 'c':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
if (ParseCallOffset() || ParseCallOffset())
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
node = ParseEncoding();
|
|
|
|
|
if (node == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new SpecialName("covariant return thunk to ", node);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
// extension ::= TC <first type> <number> _ <second type>
|
|
|
|
|
case 'C':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
BaseNode firstType = ParseType();
|
|
|
|
|
if (firstType == null || ParseNumber(true).Length == 0 || !ConsumeIf("_"))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode secondType = ParseType();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new CtorVtableSpecialName(secondType, firstType);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
// ::= TH <object name> # Thread-local initialization
|
|
|
|
|
case 'H':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
node = ParseName();
|
|
|
|
|
if (node == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new SpecialName("thread-local initialization routine for ", node);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
// ::= TW <object name> # Thread-local wrapper
|
|
|
|
|
case 'W':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
node = ParseName();
|
|
|
|
|
if (node == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new SpecialName("thread-local wrapper routine for ", node);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
default:
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
|
|
|
|
bool isVirtual = Peek() == 'v';
|
2018-09-15 15:29:18 +02:00
|
|
|
|
if (ParseCallOffset())
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
node = ParseEncoding();
|
|
|
|
|
if (node == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (isVirtual)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new SpecialName("virtual thunk to ", node);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new SpecialName("non-virtual thunk to ", node);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <CV-qualifiers> ::= [r] [V] [K] # restrict (C99), volatile, const
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private Cv ParseCvQualifiers()
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
Cv qualifiers = Cv.None;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
|
|
|
|
if (ConsumeIf("r"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
qualifiers |= Cv.Restricted;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
if (ConsumeIf("V"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
qualifiers |= Cv.Volatile;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
if (ConsumeIf("K"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
qualifiers |= Cv.Const;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return qualifiers;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// <ref-qualifier> ::= R # & ref-qualifier
|
|
|
|
|
// <ref-qualifier> ::= O # && ref-qualifier
|
|
|
|
|
private SimpleReferenceType ParseRefQualifiers()
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
Reference result = Reference.None;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
if (ConsumeIf("O"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = Reference.RValue;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
else if (ConsumeIf("R"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = Reference.LValue;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new SimpleReferenceType(result, null);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private BaseNode CreateNameNode(BaseNode prev, BaseNode name, NameParserContext context)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode result = name;
|
|
|
|
|
if (prev != null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = new NestedName(name, prev);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (context != null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
context.FinishWithTemplateArguments = false;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return result;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int ParsePositiveNumber()
|
|
|
|
|
{
|
2023-01-18 23:25:16 +01:00
|
|
|
|
ReadOnlySpan<char> part = Mangled.AsSpan(_position);
|
|
|
|
|
int numberLength = 0;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
for (; numberLength < part.Length; numberLength++)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (!char.IsDigit(part[numberLength]))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += numberLength;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (numberLength == 0)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 23:25:16 +01:00
|
|
|
|
return int.Parse(part[..numberLength]);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private string ParseNumber(bool isSigned = false)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (isSigned)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
ConsumeIf("n");
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (Count() == 0 || !char.IsDigit(Mangled[_position]))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 23:25:16 +01:00
|
|
|
|
ReadOnlySpan<char> part = Mangled.AsSpan(_position);
|
|
|
|
|
int numberLength = 0;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
for (; numberLength < part.Length; numberLength++)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (!char.IsDigit(part[numberLength]))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += numberLength;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2023-01-18 23:25:16 +01:00
|
|
|
|
return new string(part[..numberLength]);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <source-name> ::= <positive length number> <identifier>
|
|
|
|
|
private BaseNode ParseSourceName()
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
int length = ParsePositiveNumber();
|
|
|
|
|
if (Count() < length || length <= 0)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
string name = Mangled.Substring(_position, length);
|
|
|
|
|
_position += length;
|
|
|
|
|
if (name.StartsWith("_GLOBAL__N"))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return new NameType("(anonymous namespace)");
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new NameType(name);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <operator-name> ::= nw # new
|
|
|
|
|
// ::= na # new[]
|
|
|
|
|
// ::= dl # delete
|
|
|
|
|
// ::= da # delete[]
|
|
|
|
|
// ::= ps # + (unary)
|
|
|
|
|
// ::= ng # - (unary)
|
|
|
|
|
// ::= ad # & (unary)
|
|
|
|
|
// ::= de # * (unary)
|
|
|
|
|
// ::= co # ~
|
|
|
|
|
// ::= pl # +
|
|
|
|
|
// ::= mi # -
|
|
|
|
|
// ::= ml # *
|
|
|
|
|
// ::= dv # /
|
|
|
|
|
// ::= rm # %
|
|
|
|
|
// ::= an # &
|
|
|
|
|
// ::= or # |
|
|
|
|
|
// ::= eo # ^
|
|
|
|
|
// ::= aS # =
|
|
|
|
|
// ::= pL # +=
|
|
|
|
|
// ::= mI # -=
|
|
|
|
|
// ::= mL # *=
|
|
|
|
|
// ::= dV # /=
|
|
|
|
|
// ::= rM # %=
|
|
|
|
|
// ::= aN # &=
|
|
|
|
|
// ::= oR # |=
|
|
|
|
|
// ::= eO # ^=
|
|
|
|
|
// ::= ls # <<
|
|
|
|
|
// ::= rs # >>
|
|
|
|
|
// ::= lS # <<=
|
|
|
|
|
// ::= rS # >>=
|
|
|
|
|
// ::= eq # ==
|
|
|
|
|
// ::= ne # !=
|
|
|
|
|
// ::= lt # <
|
|
|
|
|
// ::= gt # >
|
|
|
|
|
// ::= le # <=
|
|
|
|
|
// ::= ge # >=
|
|
|
|
|
// ::= ss # <=>
|
|
|
|
|
// ::= nt # !
|
|
|
|
|
// ::= aa # &&
|
|
|
|
|
// ::= oo # ||
|
|
|
|
|
// ::= pp # ++ (postfix in <expression> context)
|
|
|
|
|
// ::= mm # -- (postfix in <expression> context)
|
|
|
|
|
// ::= cm # ,
|
|
|
|
|
// ::= pm # ->*
|
|
|
|
|
// ::= pt # ->
|
|
|
|
|
// ::= cl # ()
|
|
|
|
|
// ::= ix # []
|
|
|
|
|
// ::= qu # ?
|
|
|
|
|
// ::= cv <type> # (cast) (TODO)
|
|
|
|
|
// ::= li <source-name> # operator ""
|
|
|
|
|
// ::= v <digit> <source-name> # vendor extended operator (TODO)
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private BaseNode ParseOperatorName(NameParserContext context)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
switch (Peek())
|
|
|
|
|
{
|
|
|
|
|
case 'a':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'a':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator&&");
|
|
|
|
|
case 'd':
|
|
|
|
|
case 'n':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator&");
|
|
|
|
|
case 'N':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator&=");
|
|
|
|
|
case 'S':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator=");
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
case 'c':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'l':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator()");
|
|
|
|
|
case 'm':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator,");
|
|
|
|
|
case 'o':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator~");
|
|
|
|
|
case 'v':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
bool canParseTemplateArgsBackup = _canParseTemplateArgs;
|
|
|
|
|
bool canForwardTemplateReferenceBackup = _canForwardTemplateReference;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_canParseTemplateArgs = false;
|
|
|
|
|
_canForwardTemplateReference = canForwardTemplateReferenceBackup || context != null;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode type = ParseType();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_canParseTemplateArgs = canParseTemplateArgsBackup;
|
|
|
|
|
_canForwardTemplateReference = canForwardTemplateReferenceBackup;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (type == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (context != null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
context.CtorDtorConversion = true;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new ConversionOperatorType(type);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
case 'd':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'a':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator delete[]");
|
|
|
|
|
case 'e':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator*");
|
|
|
|
|
case 'l':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator delete");
|
|
|
|
|
case 'v':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator/");
|
|
|
|
|
case 'V':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator/=");
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
case 'e':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'o':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator^");
|
|
|
|
|
case 'O':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator^=");
|
|
|
|
|
case 'q':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator==");
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
case 'g':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'e':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator>=");
|
|
|
|
|
case 't':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator>");
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
case 'i':
|
|
|
|
|
if (Peek(1) == 'x')
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator[]");
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
case 'l':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'e':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator<=");
|
|
|
|
|
case 'i':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
BaseNode sourceName = ParseSourceName();
|
|
|
|
|
if (sourceName == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new LiteralOperator(sourceName);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 's':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator<<");
|
|
|
|
|
case 'S':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator<<=");
|
|
|
|
|
case 't':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator<");
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
case 'm':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'i':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator-");
|
|
|
|
|
case 'I':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator-=");
|
|
|
|
|
case 'l':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator*");
|
|
|
|
|
case 'L':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator*=");
|
|
|
|
|
case 'm':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator--");
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
case 'n':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'a':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator new[]");
|
|
|
|
|
case 'e':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator!=");
|
|
|
|
|
case 'g':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator-");
|
|
|
|
|
case 't':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator!");
|
|
|
|
|
case 'w':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator new");
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
case 'o':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'o':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator||");
|
|
|
|
|
case 'r':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator|");
|
|
|
|
|
case 'R':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator|=");
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
case 'p':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'm':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator->*");
|
|
|
|
|
case 's':
|
|
|
|
|
case 'l':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator+");
|
|
|
|
|
case 'L':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator+=");
|
|
|
|
|
case 'p':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator++");
|
|
|
|
|
case 't':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator->");
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
case 'q':
|
|
|
|
|
if (Peek(1) == 'u')
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator?");
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
case 'r':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'm':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator%");
|
|
|
|
|
case 'M':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator%=");
|
|
|
|
|
case 's':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator>>");
|
|
|
|
|
case 'S':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator>>=");
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
case 's':
|
|
|
|
|
if (Peek(1) == 's')
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("operator<=>");
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
case 'v':
|
|
|
|
|
// TODO: ::= v <digit> <source-name> # vendor extended operator
|
|
|
|
|
return null;
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <unqualified-name> ::= <operator-name> [<abi-tags> (TODO)]
|
|
|
|
|
// ::= <ctor-dtor-name> (TODO)
|
|
|
|
|
// ::= <source-name>
|
|
|
|
|
// ::= <unnamed-type-name> (TODO)
|
|
|
|
|
// ::= DC <source-name>+ E # structured binding declaration (TODO)
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private BaseNode ParseUnqualifiedName(NameParserContext context)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode result = null;
|
|
|
|
|
char c = Peek();
|
|
|
|
|
if (c == 'U')
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
// TODO: Unnamed Type Name
|
|
|
|
|
// throw new Exception("Unnamed Type Name not implemented");
|
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
|
else if (char.IsDigit(c))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = ParseSourceName();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
else if (ConsumeIf("DC"))
|
|
|
|
|
{
|
|
|
|
|
// TODO: Structured Binding Declaration
|
|
|
|
|
// throw new Exception("Structured Binding Declaration not implemented");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = ParseOperatorName(context);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (result != null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
// TODO: ABI Tags
|
2019-07-02 04:39:22 +02:00
|
|
|
|
// throw new Exception("ABI Tags not implemented");
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return result;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <ctor-dtor-name> ::= C1 # complete object constructor
|
|
|
|
|
// ::= C2 # base object constructor
|
|
|
|
|
// ::= C3 # complete object allocating constructor
|
|
|
|
|
// ::= D0 # deleting destructor
|
|
|
|
|
// ::= D1 # complete object destructor
|
|
|
|
|
// ::= D2 # base object destructor
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private BaseNode ParseCtorDtorName(NameParserContext context, BaseNode prev)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (prev.Type == NodeType.SpecialSubstitution && prev is SpecialSubstitution)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
((SpecialSubstitution)prev).SetExtended();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ConsumeIf("C"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
bool isInherited = ConsumeIf("I");
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
char ctorDtorType = Peek();
|
|
|
|
|
if (ctorDtorType != '1' && ctorDtorType != '2' && ctorDtorType != '3')
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (context != null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
context.CtorDtorConversion = true;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (isInherited && ParseName(context) == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new CtorDtorNameType(prev, false);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ConsumeIf("D"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
char c = Peek();
|
|
|
|
|
if (c != '0' && c != '1' && c != '2')
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (context != null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
context.CtorDtorConversion = true;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new CtorDtorNameType(prev, true);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <function-param> ::= fp <top-level CV-qualifiers> _ # L == 0, first parameter
|
|
|
|
|
// ::= fp <top-level CV-qualifiers> <parameter-2 non-negative number> _ # L == 0, second and later parameters
|
|
|
|
|
// ::= fL <L-1 non-negative number> p <top-level CV-qualifiers> _ # L > 0, first parameter
|
|
|
|
|
// ::= fL <L-1 non-negative number> p <top-level CV-qualifiers> <parameter-2 non-negative number> _ # L > 0, second and later parameters
|
|
|
|
|
private BaseNode ParseFunctionParameter()
|
|
|
|
|
{
|
|
|
|
|
if (ConsumeIf("fp"))
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
2018-12-06 12:16:24 +01:00
|
|
|
|
ParseCvQualifiers();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
|
|
|
|
if (!ConsumeIf("_"))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new FunctionParameter(ParseNumber());
|
|
|
|
|
}
|
|
|
|
|
else if (ConsumeIf("fL"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
string l1Number = ParseNumber();
|
|
|
|
|
if (l1Number == null || l1Number.Length == 0)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ConsumeIf("p"))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ignored
|
2018-12-06 12:16:24 +01:00
|
|
|
|
ParseCvQualifiers();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
|
|
|
|
if (!ConsumeIf("_"))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new FunctionParameter(ParseNumber());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <fold-expr> ::= fL <binary-operator-name> <expression> <expression>
|
|
|
|
|
// ::= fR <binary-operator-name> <expression> <expression>
|
|
|
|
|
// ::= fl <binary-operator-name> <expression>
|
|
|
|
|
// ::= fr <binary-operator-name> <expression>
|
|
|
|
|
private BaseNode ParseFoldExpression()
|
|
|
|
|
{
|
|
|
|
|
if (!ConsumeIf("f"))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
char foldKind = Peek();
|
|
|
|
|
bool hasInitializer = foldKind == 'L' || foldKind == 'R';
|
|
|
|
|
bool isLeftFold = foldKind == 'l' || foldKind == 'L';
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (!isLeftFold && !(foldKind == 'r' || foldKind == 'R'))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
string operatorName = null;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
|
|
|
|
switch (PeekString(0, 2))
|
|
|
|
|
{
|
|
|
|
|
case "aa":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "&&";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "an":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "&";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "aN":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "&=";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "aS":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "=";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "cm":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = ",";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "ds":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = ".*";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "dv":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "/";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "dV":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "/=";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "eo":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "^";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "eO":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "^=";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "eq":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "==";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "ge":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = ">=";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "gt":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = ">";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "le":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "<=";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "ls":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "<<";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "lS":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "<<=";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "lt":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "<";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "mi":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "-";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "mI":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "-=";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "ml":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "*";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "mL":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "*=";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "ne":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "!=";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "oo":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "||";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "or":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "|";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "oR":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "|=";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "pl":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "+";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "pL":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "+=";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "rm":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "%";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "rM":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = "%=";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "rs":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = ">>";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
case "rS":
|
2018-12-06 12:16:24 +01:00
|
|
|
|
operatorName = ">>=";
|
2018-09-15 15:29:18 +02:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode expression = ParseExpression();
|
|
|
|
|
if (expression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode initializer = null;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (hasInitializer)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
initializer = ParseExpression();
|
|
|
|
|
if (initializer == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (isLeftFold && initializer != null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode temp = expression;
|
|
|
|
|
expression = initializer;
|
|
|
|
|
initializer = temp;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new FoldExpression(isLeftFold, operatorName, new PackedTemplateParameterExpansion(expression), initializer);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ::= cv <type> <expression> # type (expression), conversion with one argument
|
|
|
|
|
// ::= cv <type> _ <expression>* E # type (expr-list), conversion with other than one argument
|
|
|
|
|
private BaseNode ParseConversionExpression()
|
|
|
|
|
{
|
|
|
|
|
if (!ConsumeIf("cv"))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
bool canParseTemplateArgsBackup = _canParseTemplateArgs;
|
|
|
|
|
_canParseTemplateArgs = false;
|
|
|
|
|
BaseNode type = ParseType();
|
|
|
|
|
_canParseTemplateArgs = canParseTemplateArgsBackup;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (type == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
List<BaseNode> expressions = new List<BaseNode>();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
if (ConsumeIf("_"))
|
|
|
|
|
{
|
|
|
|
|
while (!ConsumeIf("E"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode expression = ParseExpression();
|
|
|
|
|
if (expression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
expressions.Add(expression);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode expression = ParseExpression();
|
|
|
|
|
if (expression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
expressions.Add(expression);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new ConversionExpression(type, new NodeArray(expressions));
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private BaseNode ParseBinaryExpression(string name)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode leftPart = ParseExpression();
|
|
|
|
|
if (leftPart == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode rightPart = ParseExpression();
|
|
|
|
|
if (rightPart == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new BinaryExpression(leftPart, name, rightPart);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private BaseNode ParsePrefixExpression(string name)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode expression = ParseExpression();
|
|
|
|
|
if (expression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new PrefixExpression(name, expression);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// <braced-expression> ::= <expression>
|
|
|
|
|
// ::= di <field source-name> <braced-expression> # .name = expr
|
|
|
|
|
// ::= dx <index expression> <braced-expression> # [expr] = expr
|
|
|
|
|
// ::= dX <range begin expression> <range end expression> <braced-expression>
|
|
|
|
|
// # [expr ... expr] = expr
|
|
|
|
|
private BaseNode ParseBracedExpression()
|
|
|
|
|
{
|
|
|
|
|
if (Peek() == 'd')
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode bracedExpressionNode;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'i':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
BaseNode field = ParseSourceName();
|
|
|
|
|
if (field == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
bracedExpressionNode = ParseBracedExpression();
|
|
|
|
|
if (bracedExpressionNode == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new BracedExpression(field, bracedExpressionNode, false);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 'x':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
BaseNode index = ParseExpression();
|
|
|
|
|
if (index == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
bracedExpressionNode = ParseBracedExpression();
|
|
|
|
|
if (bracedExpressionNode == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new BracedExpression(index, bracedExpressionNode, true);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 'X':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
BaseNode rangeBeginExpression = ParseExpression();
|
|
|
|
|
if (rangeBeginExpression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode rangeEndExpression = ParseExpression();
|
|
|
|
|
if (rangeEndExpression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
bracedExpressionNode = ParseBracedExpression();
|
|
|
|
|
if (bracedExpressionNode == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new BracedRangeExpression(rangeBeginExpression, rangeEndExpression, bracedExpressionNode);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ParseExpression();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ::= [gs] nw <expression>* _ <type> E # new (expr-list) type
|
|
|
|
|
// ::= [gs] nw <expression>* _ <type> <initializer> # new (expr-list) type (init)
|
|
|
|
|
// ::= [gs] na <expression>* _ <type> E # new[] (expr-list) type
|
|
|
|
|
// ::= [gs] na <expression>* _ <type> <initializer> # new[] (expr-list) type (init)
|
|
|
|
|
//
|
|
|
|
|
// <initializer> ::= pi <expression>* E # parenthesized initialization
|
|
|
|
|
private BaseNode ParseNewExpression()
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
bool isGlobal = ConsumeIf("gs");
|
|
|
|
|
bool isArray = Peek(1) == 'a';
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
|
|
|
|
if (!ConsumeIf("nw") || !ConsumeIf("na"))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
List<BaseNode> expressions = new List<BaseNode>();
|
|
|
|
|
List<BaseNode> initializers = new List<BaseNode>();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
|
|
|
|
while (!ConsumeIf("_"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode expression = ParseExpression();
|
|
|
|
|
if (expression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
expressions.Add(expression);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode typeNode = ParseType();
|
|
|
|
|
if (typeNode == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ConsumeIf("pi"))
|
|
|
|
|
{
|
|
|
|
|
while (!ConsumeIf("E"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode initializer = ParseExpression();
|
|
|
|
|
if (initializer == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
initializers.Add(initializer);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (!ConsumeIf("E"))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new NewExpression(new NodeArray(expressions), typeNode, new NodeArray(initializers), isGlobal, isArray);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// <expression> ::= <unary operator-name> <expression>
|
|
|
|
|
// ::= <binary operator-name> <expression> <expression>
|
|
|
|
|
// ::= <ternary operator-name> <expression> <expression> <expression>
|
|
|
|
|
// ::= pp_ <expression> # prefix ++
|
|
|
|
|
// ::= mm_ <expression> # prefix --
|
|
|
|
|
// ::= cl <expression>+ E # expression (expr-list), call
|
|
|
|
|
// ::= cv <type> <expression> # type (expression), conversion with one argument
|
|
|
|
|
// ::= cv <type> _ <expression>* E # type (expr-list), conversion with other than one argument
|
|
|
|
|
// ::= tl <type> <braced-expression>* E # type {expr-list}, conversion with braced-init-list argument
|
|
|
|
|
// ::= il <braced-expression>* E # {expr-list}, braced-init-list in any other context
|
|
|
|
|
// ::= [gs] nw <expression>* _ <type> E # new (expr-list) type
|
|
|
|
|
// ::= [gs] nw <expression>* _ <type> <initializer> # new (expr-list) type (init)
|
|
|
|
|
// ::= [gs] na <expression>* _ <type> E # new[] (expr-list) type
|
|
|
|
|
// ::= [gs] na <expression>* _ <type> <initializer> # new[] (expr-list) type (init)
|
|
|
|
|
// ::= [gs] dl <expression> # delete expression
|
|
|
|
|
// ::= [gs] da <expression> # delete[] expression
|
|
|
|
|
// ::= dc <type> <expression> # dynamic_cast<type> (expression)
|
|
|
|
|
// ::= sc <type> <expression> # static_cast<type> (expression)
|
|
|
|
|
// ::= cc <type> <expression> # const_cast<type> (expression)
|
|
|
|
|
// ::= rc <type> <expression> # reinterpret_cast<type> (expression)
|
|
|
|
|
// ::= ti <type> # typeid (type)
|
|
|
|
|
// ::= te <expression> # typeid (expression)
|
|
|
|
|
// ::= st <type> # sizeof (type)
|
|
|
|
|
// ::= sz <expression> # sizeof (expression)
|
|
|
|
|
// ::= at <type> # alignof (type)
|
|
|
|
|
// ::= az <expression> # alignof (expression)
|
|
|
|
|
// ::= nx <expression> # noexcept (expression)
|
|
|
|
|
// ::= <template-param>
|
|
|
|
|
// ::= <function-param>
|
|
|
|
|
// ::= dt <expression> <unresolved-name> # expr.name
|
|
|
|
|
// ::= pt <expression> <unresolved-name> # expr->name
|
|
|
|
|
// ::= ds <expression> <expression> # expr.*expr
|
|
|
|
|
// ::= sZ <template-param> # sizeof...(T), size of a template parameter pack
|
|
|
|
|
// ::= sZ <function-param> # sizeof...(parameter), size of a function parameter pack
|
|
|
|
|
// ::= sP <template-arg>* E # sizeof...(T), size of a captured template parameter pack from an alias template
|
|
|
|
|
// ::= sp <expression> # expression..., pack expansion
|
|
|
|
|
// ::= tw <expression> # throw expression
|
|
|
|
|
// ::= tr # throw with no operand (rethrow)
|
|
|
|
|
// ::= <unresolved-name> # f(p), N::f(p), ::f(p),
|
|
|
|
|
// # freestanding dependent name (e.g., T::x),
|
|
|
|
|
// # objectless nonstatic member reference
|
|
|
|
|
// ::= <expr-primary>
|
|
|
|
|
private BaseNode ParseExpression()
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
bool isGlobal = ConsumeIf("gs");
|
|
|
|
|
BaseNode expression = null;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
if (Count() < 2)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (Peek())
|
|
|
|
|
{
|
|
|
|
|
case 'L':
|
|
|
|
|
return ParseExpressionPrimary();
|
|
|
|
|
case 'T':
|
|
|
|
|
return ParseTemplateParam();
|
|
|
|
|
case 'f':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
char c = Peek(1);
|
|
|
|
|
if (c == 'p' || (c == 'L' && char.IsDigit(Peek(2))))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return ParseFunctionParameter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ParseFoldExpression();
|
|
|
|
|
case 'a':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'a':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("&&");
|
|
|
|
|
case 'd':
|
|
|
|
|
case 'n':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("&");
|
|
|
|
|
case 'N':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("&=");
|
|
|
|
|
case 'S':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("=");
|
|
|
|
|
case 't':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
BaseNode type = ParseType();
|
|
|
|
|
if (type == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new EnclosedExpression("alignof (", type, ")");
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 'z':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
expression = ParseExpression();
|
|
|
|
|
if (expression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new EnclosedExpression("alignof (", expression, ")");
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
case 'c':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'c':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
BaseNode to = ParseType();
|
|
|
|
|
if (to == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode from = ParseExpression();
|
|
|
|
|
if (from == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new CastExpression("const_cast", to, from);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 'l':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
BaseNode callee = ParseExpression();
|
|
|
|
|
if (callee == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
List<BaseNode> names = new List<BaseNode>();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
while (!ConsumeIf("E"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
expression = ParseExpression();
|
|
|
|
|
if (expression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
names.Add(expression);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new CallExpression(callee, names);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 'm':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression(",");
|
|
|
|
|
case 'o':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParsePrefixExpression("~");
|
|
|
|
|
case 'v':
|
|
|
|
|
return ParseConversionExpression();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
case 'd':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode leftNode = null;
|
|
|
|
|
BaseNode rightNode = null;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'a':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
expression = ParseExpression();
|
|
|
|
|
if (expression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return expression;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new DeleteExpression(expression, isGlobal, true);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 'c':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
BaseNode type = ParseType();
|
|
|
|
|
if (type == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
expression = ParseExpression();
|
|
|
|
|
if (expression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return expression;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new CastExpression("dynamic_cast", type, expression);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 'e':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParsePrefixExpression("*");
|
|
|
|
|
case 'l':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
expression = ParseExpression();
|
|
|
|
|
if (expression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new DeleteExpression(expression, isGlobal, false);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 'n':
|
|
|
|
|
return ParseUnresolvedName();
|
|
|
|
|
case 's':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
leftNode = ParseExpression();
|
|
|
|
|
if (leftNode == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
rightNode = ParseExpression();
|
|
|
|
|
if (rightNode == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new MemberExpression(leftNode, ".*", rightNode);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 't':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
leftNode = ParseExpression();
|
|
|
|
|
if (leftNode == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
rightNode = ParseExpression();
|
|
|
|
|
if (rightNode == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new MemberExpression(leftNode, ".", rightNode);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 'v':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("/");
|
|
|
|
|
case 'V':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("/=");
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
case 'e':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'o':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("^");
|
|
|
|
|
case 'O':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("^=");
|
|
|
|
|
case 'q':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("==");
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
case 'g':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'e':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression(">=");
|
|
|
|
|
case 't':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression(">");
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
case 'i':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'x':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
BaseNode Base = ParseExpression();
|
|
|
|
|
if (Base == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode subscript = ParseExpression();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
if (Base == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new ArraySubscriptingExpression(Base, subscript);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 'l':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
List<BaseNode> bracedExpressions = new List<BaseNode>();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
while (!ConsumeIf("E"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
expression = ParseBracedExpression();
|
|
|
|
|
if (expression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
bracedExpressions.Add(expression);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new InitListExpression(null, bracedExpressions);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
case 'l':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'e':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("<=");
|
|
|
|
|
case 's':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("<<");
|
|
|
|
|
case 'S':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("<<=");
|
|
|
|
|
case 't':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("<");
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
case 'm':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'i':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("-");
|
|
|
|
|
case 'I':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("-=");
|
|
|
|
|
case 'l':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("*");
|
|
|
|
|
case 'L':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("*=");
|
|
|
|
|
case 'm':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
if (ConsumeIf("_"))
|
|
|
|
|
{
|
|
|
|
|
return ParsePrefixExpression("--");
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
expression = ParseExpression();
|
|
|
|
|
if (expression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new PostfixExpression(expression, "--");
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
case 'n':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'a':
|
|
|
|
|
case 'w':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseNewExpression();
|
|
|
|
|
case 'e':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("!=");
|
|
|
|
|
case 'g':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParsePrefixExpression("-");
|
|
|
|
|
case 't':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParsePrefixExpression("!");
|
|
|
|
|
case 'x':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
expression = ParseExpression();
|
|
|
|
|
if (expression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new EnclosedExpression("noexcept (", expression, ")");
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
case 'o':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'n':
|
|
|
|
|
return ParseUnresolvedName();
|
|
|
|
|
case 'o':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("||");
|
|
|
|
|
case 'r':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("|");
|
|
|
|
|
case 'R':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("|=");
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
case 'p':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'm':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("->*");
|
|
|
|
|
case 'l':
|
|
|
|
|
case 's':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("+");
|
|
|
|
|
case 'L':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("+=");
|
|
|
|
|
case 'p':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
if (ConsumeIf("_"))
|
|
|
|
|
{
|
|
|
|
|
return ParsePrefixExpression("++");
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
expression = ParseExpression();
|
|
|
|
|
if (expression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new PostfixExpression(expression, "++");
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 't':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
leftNode = ParseExpression();
|
|
|
|
|
if (leftNode == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
rightNode = ParseExpression();
|
|
|
|
|
if (rightNode == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new MemberExpression(leftNode, "->", rightNode);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
case 'q':
|
|
|
|
|
if (Peek(1) == 'u')
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
BaseNode condition = ParseExpression();
|
|
|
|
|
if (condition == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
leftNode = ParseExpression();
|
|
|
|
|
if (leftNode == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
rightNode = ParseExpression();
|
|
|
|
|
if (rightNode == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new ConditionalExpression(condition, leftNode, rightNode);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
case 'r':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'c':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
BaseNode to = ParseType();
|
|
|
|
|
if (to == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode from = ParseExpression();
|
|
|
|
|
if (from == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new CastExpression("reinterpret_cast", to, from);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 'm':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("%");
|
|
|
|
|
case 'M':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression("%");
|
|
|
|
|
case 's':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression(">>");
|
|
|
|
|
case 'S':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseBinaryExpression(">>=");
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
case 's':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'c':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
BaseNode to = ParseType();
|
|
|
|
|
if (to == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode from = ParseExpression();
|
|
|
|
|
if (from == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new CastExpression("static_cast", to, from);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 'p':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
expression = ParseExpression();
|
|
|
|
|
if (expression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new PackedTemplateParameterExpansion(expression);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 'r':
|
|
|
|
|
return ParseUnresolvedName();
|
|
|
|
|
case 't':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
BaseNode enclosedType = ParseType();
|
|
|
|
|
if (enclosedType == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new EnclosedExpression("sizeof (", enclosedType, ")");
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 'z':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
expression = ParseExpression();
|
|
|
|
|
if (expression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new EnclosedExpression("sizeof (", expression, ")");
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 'Z':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
BaseNode sizeofParamNode = null;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
switch (Peek())
|
|
|
|
|
{
|
|
|
|
|
case 'T':
|
|
|
|
|
// FIXME: ??? Not entire sure if it's right
|
2018-12-06 12:16:24 +01:00
|
|
|
|
sizeofParamNode = ParseFunctionParameter();
|
|
|
|
|
if (sizeofParamNode == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new EnclosedExpression("sizeof...(", new PackedTemplateParameterExpansion(sizeofParamNode), ")");
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 'f':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
sizeofParamNode = ParseFunctionParameter();
|
|
|
|
|
if (sizeofParamNode == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new EnclosedExpression("sizeof...(", sizeofParamNode, ")");
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
case 'P':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
List<BaseNode> arguments = new List<BaseNode>();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
while (!ConsumeIf("E"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode argument = ParseTemplateArgument();
|
|
|
|
|
if (argument == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
arguments.Add(argument);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new EnclosedExpression("sizeof...(", new NodeArray(arguments), ")");
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
case 't':
|
|
|
|
|
switch (Peek(1))
|
|
|
|
|
{
|
|
|
|
|
case 'e':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
expression = ParseExpression();
|
|
|
|
|
if (expression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new EnclosedExpression("typeid (", expression, ")");
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 't':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode enclosedType = ParseExpression();
|
|
|
|
|
if (enclosedType == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new EnclosedExpression("typeid (", enclosedType, ")");
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 'l':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
BaseNode typeNode = ParseType();
|
|
|
|
|
if (typeNode == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
List<BaseNode> bracedExpressions = new List<BaseNode>();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
while (!ConsumeIf("E"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
expression = ParseBracedExpression();
|
|
|
|
|
if (expression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
bracedExpressions.Add(expression);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new InitListExpression(typeNode, bracedExpressions);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
case 'r':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return new NameType("throw");
|
|
|
|
|
case 'w':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position += 2;
|
|
|
|
|
expression = ParseExpression();
|
|
|
|
|
if (expression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new ThrowExpression(expression);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (char.IsDigit(Peek()))
|
|
|
|
|
{
|
|
|
|
|
return ParseUnresolvedName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private BaseNode ParseIntegerLiteral(string literalName)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
string number = ParseNumber(true);
|
|
|
|
|
if (number == null || number.Length == 0 || !ConsumeIf("E"))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new IntegerLiteral(literalName, number);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <expr-primary> ::= L <type> <value number> E # integer literal
|
|
|
|
|
// ::= L <type> <value float> E # floating literal (TODO)
|
|
|
|
|
// ::= L <string type> E # string literal
|
|
|
|
|
// ::= L <nullptr type> E # nullptr literal (i.e., "LDnE")
|
|
|
|
|
// ::= L <pointer type> 0 E # null pointer template argument
|
|
|
|
|
// ::= L <type> <real-part float> _ <imag-part float> E # complex floating point literal (C 2000)
|
|
|
|
|
// ::= L _Z <encoding> E # external name
|
|
|
|
|
private BaseNode ParseExpressionPrimary()
|
|
|
|
|
{
|
|
|
|
|
if (!ConsumeIf("L"))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (Peek())
|
|
|
|
|
{
|
|
|
|
|
case 'w':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseIntegerLiteral("wchar_t");
|
|
|
|
|
case 'b':
|
|
|
|
|
if (ConsumeIf("b0E"))
|
|
|
|
|
{
|
|
|
|
|
return new NameType("false", NodeType.BooleanExpression);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ConsumeIf("b1E"))
|
|
|
|
|
{
|
|
|
|
|
return new NameType("true", NodeType.BooleanExpression);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
case 'c':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseIntegerLiteral("char");
|
|
|
|
|
case 'a':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseIntegerLiteral("signed char");
|
|
|
|
|
case 'h':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseIntegerLiteral("unsigned char");
|
|
|
|
|
case 's':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseIntegerLiteral("short");
|
|
|
|
|
case 't':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseIntegerLiteral("unsigned short");
|
|
|
|
|
case 'i':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseIntegerLiteral("");
|
|
|
|
|
case 'j':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseIntegerLiteral("u");
|
|
|
|
|
case 'l':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseIntegerLiteral("l");
|
|
|
|
|
case 'm':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseIntegerLiteral("ul");
|
|
|
|
|
case 'x':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseIntegerLiteral("ll");
|
|
|
|
|
case 'y':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseIntegerLiteral("ull");
|
|
|
|
|
case 'n':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseIntegerLiteral("__int128");
|
|
|
|
|
case 'o':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
return ParseIntegerLiteral("unsigned __int128");
|
|
|
|
|
case 'd':
|
|
|
|
|
case 'e':
|
|
|
|
|
case 'f':
|
|
|
|
|
// TODO: floating literal
|
|
|
|
|
return null;
|
|
|
|
|
case '_':
|
|
|
|
|
if (ConsumeIf("_Z"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode encoding = ParseEncoding();
|
|
|
|
|
if (encoding != null && ConsumeIf("E"))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return encoding;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
case 'T':
|
|
|
|
|
return null;
|
|
|
|
|
default:
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode type = ParseType();
|
|
|
|
|
if (type == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
string number = ParseNumber();
|
|
|
|
|
if (number == null || number.Length == 0 || !ConsumeIf("E"))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new IntegerCastExpression(type, number);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <decltype> ::= Dt <expression> E # decltype of an id-expression or class member access (C++0x)
|
|
|
|
|
// ::= DT <expression> E # decltype of an expression (C++0x)
|
|
|
|
|
private BaseNode ParseDecltype()
|
|
|
|
|
{
|
|
|
|
|
if (!ConsumeIf("D") || (!ConsumeIf("t") && !ConsumeIf("T")))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode expression = ParseExpression();
|
|
|
|
|
if (expression == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ConsumeIf("E"))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new EnclosedExpression("decltype(", expression, ")");
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <template-param> ::= T_ # first template parameter
|
|
|
|
|
// ::= T <parameter-2 non-negative number> _
|
|
|
|
|
// <template-template-param> ::= <template-param>
|
|
|
|
|
// ::= <substitution>
|
|
|
|
|
private BaseNode ParseTemplateParam()
|
|
|
|
|
{
|
|
|
|
|
if (!ConsumeIf("T"))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
int index = 0;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
if (!ConsumeIf("_"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
index = ParsePositiveNumber();
|
|
|
|
|
if (index < 0)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
index++;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
if (!ConsumeIf("_"))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 5.1.8: TODO: lambda?
|
|
|
|
|
// if (IsParsingLambdaParameters)
|
|
|
|
|
// return new NameType("auto");
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (_canForwardTemplateReference)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
ForwardTemplateReference forwardTemplateReference = new ForwardTemplateReference(index);
|
|
|
|
|
_forwardTemplateReferenceList.Add(forwardTemplateReference);
|
|
|
|
|
return forwardTemplateReference;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (index >= _templateParamList.Count)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return _templateParamList[index];
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <template-args> ::= I <template-arg>+ E
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private BaseNode ParseTemplateArguments(bool hasContext = false)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
if (!ConsumeIf("I"))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (hasContext)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_templateParamList.Clear();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
List<BaseNode> args = new List<BaseNode>();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
while (!ConsumeIf("E"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (hasContext)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
List<BaseNode> templateParamListTemp = new List<BaseNode>(_templateParamList);
|
|
|
|
|
BaseNode templateArgument = ParseTemplateArgument();
|
|
|
|
|
_templateParamList = templateParamListTemp;
|
|
|
|
|
if (templateArgument == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
args.Add(templateArgument);
|
|
|
|
|
if (templateArgument.GetType().Equals(NodeType.PackedTemplateArgument))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
templateArgument = new PackedTemplateParameter(((NodeArray)templateArgument).Nodes);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_templateParamList.Add(templateArgument);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode templateArgument = ParseTemplateArgument();
|
|
|
|
|
if (templateArgument == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
args.Add(templateArgument);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new TemplateArguments(args);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// <template-arg> ::= <type> # type or template
|
|
|
|
|
// ::= X <expression> E # expression
|
|
|
|
|
// ::= <expr-primary> # simple expressions
|
|
|
|
|
// ::= J <template-arg>* E # argument pack
|
|
|
|
|
private BaseNode ParseTemplateArgument()
|
|
|
|
|
{
|
|
|
|
|
switch (Peek())
|
|
|
|
|
{
|
|
|
|
|
// X <expression> E
|
|
|
|
|
case 'X':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
|
|
|
|
BaseNode expression = ParseExpression();
|
|
|
|
|
if (expression == null || !ConsumeIf("E"))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return expression;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
// <expr-primary>
|
|
|
|
|
case 'L':
|
|
|
|
|
return ParseExpressionPrimary();
|
|
|
|
|
// J <template-arg>* E
|
|
|
|
|
case 'J':
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_position++;
|
|
|
|
|
List<BaseNode> templateArguments = new List<BaseNode>();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
while (!ConsumeIf("E"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode templateArgument = ParseTemplateArgument();
|
|
|
|
|
if (templateArgument == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
templateArguments.Add(templateArgument);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new NodeArray(templateArguments, NodeType.PackedTemplateArgument);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
// <type>
|
|
|
|
|
default:
|
|
|
|
|
return ParseType();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class NameParserContext
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
public CvType Cv;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
public SimpleReferenceType Ref;
|
|
|
|
|
public bool FinishWithTemplateArguments;
|
|
|
|
|
public bool CtorDtorConversion;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// <unresolved-type> ::= <template-param> [ <template-args> ] # T:: or T<X,Y>::
|
|
|
|
|
// ::= <decltype> # decltype(p)::
|
|
|
|
|
// ::= <substitution>
|
|
|
|
|
private BaseNode ParseUnresolvedType()
|
|
|
|
|
{
|
|
|
|
|
if (Peek() == 'T')
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode templateParam = ParseTemplateParam();
|
|
|
|
|
if (templateParam == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_substitutionList.Add(templateParam);
|
|
|
|
|
return templateParam;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
else if (Peek() == 'D')
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode declType = ParseDecltype();
|
|
|
|
|
if (declType == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_substitutionList.Add(declType);
|
|
|
|
|
return declType;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
return ParseSubstitution();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <simple-id> ::= <source-name> [ <template-args> ]
|
|
|
|
|
private BaseNode ParseSimpleId()
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode sourceName = ParseSourceName();
|
|
|
|
|
if (sourceName == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Peek() == 'I')
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode templateArguments = ParseTemplateArguments();
|
|
|
|
|
if (templateArguments == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new NameTypeWithTemplateArguments(sourceName, templateArguments);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return sourceName;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <destructor-name> ::= <unresolved-type> # e.g., ~T or ~decltype(f())
|
|
|
|
|
// ::= <simple-id> # e.g., ~A<2*N>
|
|
|
|
|
private BaseNode ParseDestructorName()
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode node;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
if (char.IsDigit(Peek()))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
node = ParseSimpleId();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
node = ParseUnresolvedType();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (node == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new DtorName(node);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <base-unresolved-name> ::= <simple-id> # unresolved name
|
|
|
|
|
// extension ::= <operator-name> # unresolved operator-function-id
|
|
|
|
|
// extension ::= <operator-name> <template-args> # unresolved operator template-id
|
|
|
|
|
// ::= on <operator-name> # unresolved operator-function-id
|
|
|
|
|
// ::= on <operator-name> <template-args> # unresolved operator template-id
|
|
|
|
|
// ::= dn <destructor-name> # destructor or pseudo-destructor;
|
|
|
|
|
// # e.g. ~X or ~X<N-1>
|
|
|
|
|
private BaseNode ParseBaseUnresolvedName()
|
|
|
|
|
{
|
|
|
|
|
if (char.IsDigit(Peek()))
|
|
|
|
|
{
|
|
|
|
|
return ParseSimpleId();
|
|
|
|
|
}
|
|
|
|
|
else if (ConsumeIf("dn"))
|
|
|
|
|
{
|
|
|
|
|
return ParseDestructorName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ConsumeIf("on");
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode operatorName = ParseOperatorName(null);
|
|
|
|
|
if (operatorName == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Peek() == 'I')
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode templateArguments = ParseTemplateArguments();
|
|
|
|
|
if (templateArguments == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new NameTypeWithTemplateArguments(operatorName, templateArguments);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return operatorName;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <unresolved-name> ::= [gs] <base-unresolved-name> # x or (with "gs") ::x
|
|
|
|
|
// ::= sr <unresolved-type> <base-unresolved-name> # T::x / decltype(p)::x
|
|
|
|
|
// ::= srN <unresolved-type> <unresolved-qualifier-level>+ E <base-unresolved-name>
|
|
|
|
|
// # T::N::x /decltype(p)::N::x
|
|
|
|
|
// ::= [gs] sr <unresolved-qualifier-level>+ E <base-unresolved-name>
|
|
|
|
|
// # A::x, N::y, A<T>::z; "gs" means leading "::"
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private BaseNode ParseUnresolvedName(NameParserContext context = null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode result = null;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
if (ConsumeIf("srN"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = ParseUnresolvedType();
|
|
|
|
|
if (result == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Peek() == 'I')
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode templateArguments = ParseTemplateArguments();
|
|
|
|
|
if (templateArguments == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = new NameTypeWithTemplateArguments(result, templateArguments);
|
|
|
|
|
if (result == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (!ConsumeIf("E"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode simpleId = ParseSimpleId();
|
|
|
|
|
if (simpleId == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = new QualifiedName(result, simpleId);
|
|
|
|
|
if (result == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode baseName = ParseBaseUnresolvedName();
|
|
|
|
|
if (baseName == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new QualifiedName(result, baseName);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
bool isGlobal = ConsumeIf("gs");
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
|
|
|
|
// ::= [gs] <base-unresolved-name> # x or (with "gs") ::x
|
|
|
|
|
if (!ConsumeIf("sr"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = ParseBaseUnresolvedName();
|
|
|
|
|
if (result == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (isGlobal)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = new GlobalQualifiedName(result);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return result;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ::= [gs] sr <unresolved-qualifier-level>+ E <base-unresolved-name>
|
|
|
|
|
if (char.IsDigit(Peek()))
|
|
|
|
|
{
|
|
|
|
|
do
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode qualifier = ParseSimpleId();
|
|
|
|
|
if (qualifier == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (result != null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = new QualifiedName(result, qualifier);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
|
else if (isGlobal)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = new GlobalQualifiedName(qualifier);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = qualifier;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (result == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
} while (!ConsumeIf("E"));
|
|
|
|
|
}
|
2019-07-02 04:39:22 +02:00
|
|
|
|
// ::= sr <unresolved-type> [template-args] <base-unresolved-name> # T::x / decltype(p)::x
|
2018-09-15 15:29:18 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = ParseUnresolvedType();
|
|
|
|
|
if (result == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Peek() == 'I')
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode templateArguments = ParseTemplateArguments();
|
|
|
|
|
if (templateArguments == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = new NameTypeWithTemplateArguments(result, templateArguments);
|
|
|
|
|
if (result == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (result == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode baseUnresolvedName = ParseBaseUnresolvedName();
|
|
|
|
|
if (baseUnresolvedName == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new QualifiedName(result, baseUnresolvedName);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <unscoped-name> ::= <unqualified-name>
|
|
|
|
|
// ::= St <unqualified-name> # ::std::
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private BaseNode ParseUnscopedName(NameParserContext context)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
if (ConsumeIf("St"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode unresolvedName = ParseUnresolvedName(context);
|
|
|
|
|
if (unresolvedName == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new StdQualifiedName(unresolvedName);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return ParseUnresolvedName(context);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <nested-name> ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix (TODO)> <unqualified-name> E
|
|
|
|
|
// ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix (TODO)> <template-args (TODO)> E
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private BaseNode ParseNestedName(NameParserContext context)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
// Impossible in theory
|
|
|
|
|
if (Consume() != 'N')
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode result = null;
|
|
|
|
|
CvType cv = new CvType(ParseCvQualifiers(), null);
|
|
|
|
|
if (context != null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
context.Cv = cv;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SimpleReferenceType Ref = ParseRefQualifiers();
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (context != null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
context.Ref = Ref;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ConsumeIf("St"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = new NameType("std");
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (!ConsumeIf("E"))
|
|
|
|
|
{
|
|
|
|
|
// <data-member-prefix> end
|
|
|
|
|
if (ConsumeIf("M"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (result == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
|
char c = Peek();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
|
|
|
|
// TODO: template args
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (c == 'T')
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode templateParam = ParseTemplateParam();
|
|
|
|
|
if (templateParam == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = CreateNameNode(result, templateParam, context);
|
|
|
|
|
_substitutionList.Add(result);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <template-prefix> <template-args>
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (c == 'I')
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode templateArgument = ParseTemplateArguments(context != null);
|
|
|
|
|
if (templateArgument == null || result == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = new NameTypeWithTemplateArguments(result, templateArgument);
|
|
|
|
|
if (context != null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
context.FinishWithTemplateArguments = true;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_substitutionList.Add(result);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <decltype>
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (c == 'D' && (Peek(1) == 't' || Peek(1) == 'T'))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode decltype = ParseDecltype();
|
|
|
|
|
if (decltype == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = CreateNameNode(result, decltype, context);
|
|
|
|
|
_substitutionList.Add(result);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <substitution>
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (c == 'S' && Peek(1) != 't')
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode substitution = ParseSubstitution();
|
|
|
|
|
if (substitution == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = CreateNameNode(result, substitution, context);
|
|
|
|
|
if (result != substitution)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_substitutionList.Add(substitution);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <ctor-dtor-name> of ParseUnqualifiedName
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (c == 'C' || (c == 'D' && Peek(1) != 'C'))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
// We cannot have nothing before this
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (result == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode ctOrDtorName = ParseCtorDtorName(context, result);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (ctOrDtorName == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = CreateNameNode(result, ctOrDtorName, context);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
|
|
|
|
// TODO: ABI Tags (before)
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (result == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_substitutionList.Add(result);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode unqualifiedName = ParseUnqualifiedName(context);
|
|
|
|
|
if (unqualifiedName == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
|
result = CreateNameNode(result, unqualifiedName, context);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_substitutionList.Add(result);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (result == null || _substitutionList.Count == 0)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_substitutionList.RemoveAt(_substitutionList.Count - 1);
|
|
|
|
|
return result;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <discriminator> ::= _ <non-negative number> # when number < 10
|
|
|
|
|
// ::= __ <non-negative number> _ # when number >= 10
|
|
|
|
|
private void ParseDiscriminator()
|
|
|
|
|
{
|
|
|
|
|
if (Count() == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// We ignore the discriminator, we don't need it.
|
|
|
|
|
if (ConsumeIf("_"))
|
|
|
|
|
{
|
|
|
|
|
ConsumeIf("_");
|
|
|
|
|
while (char.IsDigit(Peek()) && Count() != 0)
|
|
|
|
|
{
|
|
|
|
|
Consume();
|
|
|
|
|
}
|
|
|
|
|
ConsumeIf("_");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <local-name> ::= Z <function encoding> E <entity name> [<discriminator>]
|
|
|
|
|
// ::= Z <function encoding> E s [<discriminator>]
|
|
|
|
|
// ::= Z <function encoding> Ed [ <parameter number> ] _ <entity name>
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private BaseNode ParseLocalName(NameParserContext context)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
if (!ConsumeIf("Z"))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode encoding = ParseEncoding();
|
|
|
|
|
if (encoding == null || !ConsumeIf("E"))
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode entityName;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
if (ConsumeIf("s"))
|
|
|
|
|
{
|
|
|
|
|
ParseDiscriminator();
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new LocalName(encoding, new NameType("string literal"));
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
else if (ConsumeIf("d"))
|
|
|
|
|
{
|
|
|
|
|
ParseNumber(true);
|
|
|
|
|
if (!ConsumeIf("_"))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
entityName = ParseName(context);
|
|
|
|
|
if (entityName == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new LocalName(encoding, entityName);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
entityName = ParseName(context);
|
|
|
|
|
if (entityName == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ParseDiscriminator();
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new LocalName(encoding, entityName);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <name> ::= <nested-name>
|
|
|
|
|
// ::= <unscoped-name>
|
|
|
|
|
// ::= <unscoped-template-name> <template-args>
|
|
|
|
|
// ::= <local-name> # See Scope Encoding below (TODO)
|
2018-12-06 12:16:24 +01:00
|
|
|
|
private BaseNode ParseName(NameParserContext context = null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
ConsumeIf("L");
|
|
|
|
|
|
|
|
|
|
if (Peek() == 'N')
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return ParseNestedName(context);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Peek() == 'Z')
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return ParseLocalName(context);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Peek() == 'S' && Peek(1) != 't')
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode substitution = ParseSubstitution();
|
|
|
|
|
if (substitution == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Peek() != 'I')
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode templateArguments = ParseTemplateArguments(context != null);
|
|
|
|
|
if (templateArguments == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (context != null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
context.FinishWithTemplateArguments = true;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new NameTypeWithTemplateArguments(substitution, templateArguments);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode result = ParseUnscopedName(context);
|
|
|
|
|
if (result == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Peek() == 'I')
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
_substitutionList.Add(result);
|
|
|
|
|
BaseNode templateArguments = ParseTemplateArguments(context != null);
|
|
|
|
|
if (templateArguments == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (context != null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
context.FinishWithTemplateArguments = true;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new NameTypeWithTemplateArguments(result, templateArguments);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return result;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool IsEncodingEnd()
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
char c = Peek();
|
|
|
|
|
return Count() == 0 || c == 'E' || c == '.' || c == '_';
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <encoding> ::= <function name> <bare-function-type>
|
|
|
|
|
// ::= <data name>
|
|
|
|
|
// ::= <special-name>
|
|
|
|
|
private BaseNode ParseEncoding()
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
NameParserContext context = new NameParserContext();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
if (Peek() == 'T' || (Peek() == 'G' && Peek(1) == 'V'))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return ParseSpecialName(context);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode name = ParseName(context);
|
|
|
|
|
if (name == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: compute template refs here
|
|
|
|
|
|
|
|
|
|
if (IsEncodingEnd())
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return name;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Ua9enable_ifI
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode returnType = null;
|
|
|
|
|
if (!context.CtorDtorConversion && context.FinishWithTemplateArguments)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
returnType = ParseType();
|
|
|
|
|
if (returnType == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ConsumeIf("v"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new EncodedFunction(name, null, context.Cv, context.Ref, null, returnType);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<BaseNode> Params = new List<BaseNode>();
|
|
|
|
|
|
|
|
|
|
// backup because that can be destroyed by parseType
|
2018-12-06 12:16:24 +01:00
|
|
|
|
CvType cv = context.Cv;
|
|
|
|
|
SimpleReferenceType Ref = context.Ref;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
|
|
|
|
while (!IsEncodingEnd())
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode param = ParseType();
|
|
|
|
|
if (param == null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
Params.Add(param);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return new EncodedFunction(name, new NodeArray(Params), cv, Ref, null, returnType);
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <mangled-name> ::= _Z <encoding>
|
|
|
|
|
// ::= <type>
|
|
|
|
|
private BaseNode Parse()
|
|
|
|
|
{
|
|
|
|
|
if (ConsumeIf("_Z"))
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode encoding = ParseEncoding();
|
|
|
|
|
if (encoding != null && Count() == 0)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return encoding;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
BaseNode type = ParseType();
|
|
|
|
|
if (type != null && Count() == 0)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return type;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
public static string Parse(string originalMangled)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
Demangler instance = new Demangler(originalMangled);
|
|
|
|
|
BaseNode resNode = instance.Parse();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (resNode != null)
|
2018-09-15 15:29:18 +02:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
StringWriter writer = new StringWriter();
|
|
|
|
|
resNode.Print(writer);
|
|
|
|
|
return writer.ToString();
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return originalMangled;
|
2018-09-15 15:29:18 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|