From 2614f10ced8c78f26c7123ee102778f4c1717872 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Fri, 10 Sep 2021 18:09:50 -0500 Subject: [PATCH] Make the actual return type of a function be the unqualified version of the type specified. This is a change that was introduced in C17. However, it actually keeps things closer to ORCA/C's historical behavior, which generally ignored qualifiers in return types. --- Parser.pas | 6 +++--- Symbol.pas | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/Parser.pas b/Parser.pas index 01e34ba..897ea15 100644 --- a/Parser.pas +++ b/Parser.pas @@ -1620,7 +1620,7 @@ while typeStack <> nil do begin {reverse the type stack} functionType: begin while tPtr^.kind = definedType do tPtr := tPtr^.dType; - tPtr2^.fType := tPtr; + tPtr2^.fType := Unqualify(tPtr); if tPtr^.kind in [functionType,arrayType] then Error(103); end; @@ -3967,7 +3967,7 @@ var {tp^.isPascal := false;} {tp^.toolNum := 0;} {tp^.dispatcher := 0;} - tp^.fType := tl; + tp^.fType := Unqualify(tl); tl := tp; NextToken; end {if} @@ -4055,7 +4055,7 @@ var {tp^.isPascal := false;} {tp^.toolNum := 0;} {tp^.dispatcher := 0;} - tp^.fType := tl; + tp^.fType := Unqualify(tl); tl := tp; end; {if} end; {NonEmptyAbstractDeclarator} diff --git a/Symbol.pas b/Symbol.pas index 61c4546..56b8dd3 100644 --- a/Symbol.pas +++ b/Symbol.pas @@ -170,6 +170,16 @@ function MakeQualifiedType (origType: typePtr; qualifiers: typeQualifierSet): { returns: pointer to the qualified type } +function Unqualify (tp: typePtr): typePtr; + +{ returns the unqualified version of a type } +{ } +{ parameters: } +{ tp - the original type } +{ } +{ returns: pointer to the unqualified type } + + function NewSymbol (name: stringPtr; itype: typePtr; class: tokenEnum; space: spaceType; state: stateKind): identPtr; @@ -1645,6 +1655,32 @@ else end; {MakeQualifiedType} +function Unqualify {tp: typePtr): typePtr}; + +{ returns the unqualified version of a type } +{ } +{ parameters: } +{ tp - the original type } +{ } +{ returns: pointer to the unqualified type } + +var + tp2: typePtr; {unqualified type} + +begin {Unqualify} +while tp^.kind = definedType do + tp := tp^.dType; +Unqualify := tp; +if tp^.qualifiers <> [] then + if not (tp^.kind in [structType,unionType]) then begin + tp2 := pointer(Malloc(sizeof(typeRecord))); + tp2^ := tp^; + tp2^.qualifiers := []; + Unqualify := tp2; + end; +end; {Unqualify} + + function NewSymbol {name: stringPtr; itype: typePtr; class: tokenEnum; space: spaceType; state: stateKind): identPtr};