From 6eef15b9309acc3299a264a5411f9d6ee1408c59 Mon Sep 17 00:00:00 2001 From: Rainer Schuetze Date: Fri, 26 May 2017 20:21:30 +0200 Subject: [PATCH] document changes to mangling of type and identifier back references --- spec/abi.dd | 88 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 71 insertions(+), 17 deletions(-) diff --git a/spec/abi.dd b/spec/abi.dd index 8705072dfe..c1612c3db8 100644 --- a/spec/abi.dd +++ b/spec/abi.dd @@ -205,31 +205,44 @@ $(H2 $(LNAME2 name_mangling, Name Mangling)) $(GRAMMAR $(GNAME MangledName): $(B _D) $(GLINK QualifiedName) $(GLINK Type) - $(B _D) $(GLINK QualifiedName) $(B M) $(GLINK Type) $(B _D) $(GLINK QualifiedName) $(B Z) $(GREEN // Internal) + ) + + $(P The $(GLINK Type) above is the type of a variable or the return type of a function. + This is never a $(GLINK TypeFunction), as the latter can only be bound to a value via a pointer + to a function or a delegate.) + $(GRAMMAR $(GNAME QualifiedName): + $(GLINK SymbolFunctionName) + $(GLINK SymbolFunctionName) $(I QualifiedName) + + $(GNAME SymbolFunctionName): $(GLINK SymbolName) - $(GLINK SymbolName) $(I QualifiedName) - $(GLINK SymbolName) $(GLINK TypeFunctionNoReturn) $(I QualifiedName) - $(GLINK SymbolName) $(B M) $(GLINK TypeModifiers)$(OPT) $(GLINK TypeFunctionNoReturn) $(I QualifiedName) + $(GLINK SymbolName) $(GLINK TypeFunctionNoReturn) + $(GLINK SymbolName) $(B M) $(GLINK TypeModifiers)$(OPT) $(GLINK TypeFunctionNoReturn) + ) + + $(P The $(B M) means that the symbol is a function that requires + a $(D this) pointer. Class or struct fields are mangled without $(B M). + To disambiguate $(B M) from being a $(GLINK Parameter) with modifier `scope`, the + following type needs to be checked for being a $(GLINK TypeFunction).) + $(GRAMMAR $(GNAME SymbolName): $(GLINK LName) $(GLINK TemplateInstanceName) - $(B 0) $(GREEN // anonymous symbols) + $(GLINK IdentifierBackRef) + $(B 0) $(GREEN // anonymous symbols) ) - $(P The $(B M) means that the symbol is a function that requires - a $(D this) pointer.) - $(P Template Instance Names have the types and values of its parameters encoded into it: ) $(GRAMMAR $(GNAME TemplateInstanceName): - $(GLINK Number) $(GLINK TemplateID) $(GLINK LName) $(GLINK TemplateArgs) $(B Z) + $(GLINK TemplateID) $(GLINK LName) $(GLINK TemplateArgs) $(B Z) $(GNAME TemplateID): $(B __T) @@ -242,13 +255,23 @@ $(H2 $(LNAME2 name_mangling, Name Mangling)) $(GNAME TemplateArg): $(GLINK TemplateArgX) $(B H) $(GLINK TemplateArgX) + ) + $(P If a template argument matches a specialized template parameter, the argument + is mangled with prefix $(B H).) + $(GRAMMAR $(GNAME TemplateArgX): $(B T) $(GLINK Type) $(B V) $(GLINK Type) $(GLINK Value) - $(B S) $(GLINK Number) $(GLINK QualifiedName) - $(B S) $(GLINK Number) $(GLINK MangledName) + $(B S) $(GLINK QualifiedName) + $(B X) $(GLINK Number) $(I ExternallyMangledName) + ) + $(P $(I ExternallyMangledName) can be any series of characters allowed on the + current platform, e.g. generated by functions with C++ linkage or annotated + with `pragma(mangle,...)`.) + + $(GRAMMAR $(GNAME Value): $(B n) $(B i) $(GLINK Number) @@ -293,7 +316,7 @@ $(H2 $(LNAME2 name_mangling, Name Mangling)) $(DT $(B n)) $(DD is for $(B null) arguments.) - $(DT $(GLINK Number)) + $(DT $(B i) $(GLINK Number)) $(DD is for positive numeric literals (including character literals).) @@ -343,7 +366,7 @@ $(H2 $(LNAME2 name_mangling, Name Mangling)) $(GLINK Namechar) $(I Namechars) ) - $(P A $(GLINK Name) is a standard D identifier.) + $(P A $(GLINK Name) is a standard D $(DDSUBLINK spec/lex, identifiers, identifier).) $(GRAMMAR $(GNAME LName): @@ -370,13 +393,41 @@ $(H2 $(LNAME2 name_mangling, Name Mangling)) the number of characters in the $(GLINK Name). ) -$(H2 $(LNAME2 type_mangling, Type Mangling)) +$(H3 $(LNAME2 back_ref, Back references)) + + $(P Any $(GLINK LName) or non-basic $(GLINK Type) (i.e. any type + that does not encode as a fixed one or two character sequence) that has been + emitted to the mangled symbol before will not be emitted again, but is referenced + by a special sequence encoding the relative position of the original occurrence in the mangled + symbol name.) + + $(P Numbers in back references are encoded with base 26 by upper case letters $(B A) - $(B Z) for higher digits + but lower case letters $(B a) - $(B z) for the last digit.) + + $(GRAMMAR + $(GNAME TypeBackRef): + $(B Q) $(GLINK NumberBackRef) + + $(GNAME IdentifierBackRef): + $(B Q) $(GLINK NumberBackRef) + + $(GNAME NumberTypeRef): + $(I lower-case-letter) + $(I upper-case-letter) $(GLINK NumberTypeRef) + ) + + $(P To distinguish between the type of the back reference a look-up of the back referenced character is necessary: + An identifier back reference always points to a digit $(B 0) to $(B 9), while a type back reference always points + to a letter.) + +$(H3 $(LNAME2 type_mangling, Type Mangling)) $(P Types are mangled using a simple linear scheme:) $(GRAMMAR $(GNAME Type): $(GLINK TypeModifiers)$(OPT) $(GLINK TypeX) + $(GLINK TypeBackRef) $(GNAME TypeX): $(GLINK TypeArray) @@ -475,15 +526,18 @@ $(H2 $(LNAME2 type_mangling, Type Mangling)) $(GNAME FuncAttr): $(GLINK FuncAttrPure) - $(GLINK FuncAttrNogc) $(GLINK FuncAttrNothrow) - $(GLINK FuncAttrProperty) $(GLINK FuncAttrRef) + $(GLINK FuncAttrProperty) + $(GLINK FuncAttrNogc) $(GLINK FuncAttrReturn) $(GLINK FuncAttrScope) $(GLINK FuncAttrTrusted) $(GLINK FuncAttrSafe) + ) + $(P Function attributes are emitted in the order as listed above.) + $(GRAMMAR $(GNAME FuncAttrPure): $(B Na) @@ -624,7 +678,7 @@ $(H2 $(LNAME2 type_mangling, Type Mangling)) $(B n) $(GNAME TypeTuple): - $(B B) $(GLINK Number) $(GLINK Parameters) + $(B B) $(GLINK Parameters) $(B Z) ) $(H2 $(LNAME2 function_calling_conventions, Function Calling Conventions))