From 7d986adf37220e1981a707745b784b078de4e3bc Mon Sep 17 00:00:00 2001 From: Ash Wolf Date: Fri, 20 Jan 2023 00:39:43 +0000 Subject: fix various inaccuracies exposed by the mach ppc plugin --- compiler_and_linker/unsorted/CDecl.c | 144 ++++++++++++++++------------------- 1 file changed, 65 insertions(+), 79 deletions(-) (limited to 'compiler_and_linker/unsorted/CDecl.c') diff --git a/compiler_and_linker/unsorted/CDecl.c b/compiler_and_linker/unsorted/CDecl.c index 8ad16a8..bc30347 100644 --- a/compiler_and_linker/unsorted/CDecl.c +++ b/compiler_and_linker/unsorted/CDecl.c @@ -606,20 +606,12 @@ static Boolean CDecl_IsEnumClassTypeOrRef(Type *type) { return IS_TYPE_CLASS(type) || IS_TYPE_ENUM(type); } -typedef enum OpMysteryValue { - OpMysteryValue0 = 0, - OpMysteryValue1 = 1, - OpMysteryValue2 = 2, - OpMysteryValue3 = 3, - OpMysteryValue4 = 4 -} OpMysteryValue; - static Boolean CDecl_CheckOperatorType(DeclInfo *declinfo, Boolean flag) { FuncArg *args; FuncArg *secondarg; Type *functype; - short r27; - Boolean r6; + short argCount; + Boolean isMethod; if (!IS_TYPE_FUNC(declinfo->thetype)) { CError_Error(CErrorStr193); @@ -630,7 +622,7 @@ static Boolean CDecl_CheckOperatorType(DeclInfo *declinfo, Boolean flag) { args = TYPE_FUNC(declinfo->thetype)->args; if (args) { if (args != &elipsis && args != &oldstyle) { - r27 = OpMysteryValue1; + argCount = 1; if (args->dexpr) { switch (declinfo->x3E) { case TK_NEW: @@ -645,11 +637,7 @@ static Boolean CDecl_CheckOperatorType(DeclInfo *declinfo, Boolean flag) { secondarg = args->next; if (secondarg) { - //r27 = ((secondarg != &elipsis && !secondarg->next) != 0) ? OpMysteryValue2 : OpMysteryValue3; - if ((secondarg != &elipsis && !secondarg->next) != 0) - r27 = OpMysteryValue2; - else - r27 = OpMysteryValue3; + argCount = ((secondarg != &elipsis && !secondarg->next) != 0) ? 2 : 3; if (secondarg->dexpr) { switch (declinfo->x3E) { case '(': @@ -664,63 +652,66 @@ static Boolean CDecl_CheckOperatorType(DeclInfo *declinfo, Boolean flag) { } } } else { - r27 = OpMysteryValue3; + argCount = 3; } } else { CError_Error(CErrorStr193); return 0; } - r6 = flag && IS_TYPEFUNC_METHOD(TYPE_FUNC(declinfo->thetype)) && !TYPE_METHOD(declinfo->thetype)->x26; + isMethod = flag && + IS_TYPEFUNC_METHOD(TYPE_FUNC(declinfo->thetype)) && + !TYPE_METHOD(declinfo->thetype)->x26; + switch (declinfo->x3E) { case TK_NEW: case TK_NEW_ARRAY: - if (r6 || !is_typesame(functype, (Type *) &void_ptr) || r27 < OpMysteryValue1 || args->type != CABI_GetSizeTType()) { + if (isMethod || !is_typesame(functype, TYPE(&void_ptr)) || argCount < 1 || args->type != CABI_GetSizeTType()) { CError_Error(CErrorStr193); return 0; } return 1; case TK_DELETE: case TK_DELETE_ARRAY: - if (r6 || !IS_TYPE_VOID(functype) || r27 < OpMysteryValue1 || !is_typesame(args->type, (Type *) &void_ptr)) { + if (isMethod || !IS_TYPE_VOID(functype) || argCount < 1 || !is_typesame(args->type, TYPE(&void_ptr))) { CError_Error(CErrorStr193); return 0; } return 1; case '=': - if (!r6) { + if (!isMethod) { CError_Error(CErrorStr193); return 0; } break; case '(': - if (!r6) { + if (!isMethod) { CError_Error(CErrorStr193); return 0; } return 1; case '[': - if (!r6) { + if (!isMethod) { CError_Error(CErrorStr193); return 0; } break; case TK_ARROW: - if (r27 != OpMysteryValue1 || r6 == 0) { + if (argCount != 1 || isMethod == 0) { CError_Error(CErrorStr193); return 0; } return 1; case TK_INCREMENT: case TK_DECREMENT: - if (r27 == OpMysteryValue2 && secondarg->type != (Type *) &stsignedint) { + if (argCount == 2 && secondarg->type != TYPE(&stsignedint)) { CError_Error(CErrorStr193); return 0; } break; } - if (flag && !r6) { + if (flag && !isMethod) { CError_Error(CErrorStr193); return 0; } @@ -732,11 +723,11 @@ static Boolean CDecl_CheckOperatorType(DeclInfo *declinfo, Boolean flag) { case '-': case TK_INCREMENT: case TK_DECREMENT: - if (r27 != OpMysteryValue1) + if (argCount != 1) goto whatever; case '!': case '~': - if (r27 == OpMysteryValue1) { + if (argCount == 1) { if (flag || CDecl_IsEnumClassTypeOrRef(args->type)) return 1; } @@ -772,7 +763,7 @@ static Boolean CDecl_CheckOperatorType(DeclInfo *declinfo, Boolean flag) { case TK_DOT_STAR: case TK_ARROW_STAR: whatever: - if (r27 == OpMysteryValue2) { + if (argCount == 2) { if (flag || CDecl_IsEnumClassTypeOrRef(args->type) || CDecl_IsEnumClassTypeOrRef(secondarg->type)) return 1; } @@ -1408,12 +1399,12 @@ static void CDecl_FuncRedeclCheck(Object *obj, DeclInfo *declinfo, Boolean flag) } Object *CDecl_GetFunctionObject(DeclInfo *declinfo, NameSpace *nspace, Boolean *pflag, Boolean someotherflag) { - Boolean r27; - Object *obj; - Type *type; NameSpace *nspace2; + Type *type; + Object *obj; NameSpaceObjectList *list; TypeMemberFunc tmp; + Boolean r27; Boolean outflag; r27 = 0; @@ -1429,14 +1420,14 @@ Object *CDecl_GetFunctionObject(DeclInfo *declinfo, NameSpace *nspace, Boolean * case TYPEFUNC: case TYPEARRAY: CError_Error(CErrorStr128); - TYPE_FUNC(declinfo->thetype)->functype = (Type *) &stsignedint; + TYPE_FUNC(declinfo->thetype)->functype = TYPE(&stsignedint); break; } if (nspace2->theclass) { CError_ASSERT(1969, declinfo->name); if (!nspace2->theclass->size) - CDecl_CompleteType((Type *) nspace2->theclass); + CDecl_CompleteType(TYPE(nspace2->theclass)); if (!(list = CScope_GetLocalObject(nspace2, declinfo->name))) { CError_Error(CErrorStr140, declinfo->name->name); return NULL; @@ -1630,7 +1621,7 @@ void CDecl_TypedefDeclarator(DeclInfo *declinfo) { CBrowse_NewTypedef(nspace, declinfo->name, declinfo->file, declinfo->file2, declinfo->x60, CPrep_BrowserFileOffset()); } -static void CDecl_DataDeclarator(DeclInfo *declinfo, short access, Boolean flag) { +static void CDecl_DataDeclarator(DeclInfo *declinfo, AccessType access, Boolean flag) { NameSpaceObjectList *list; Object *obj; NameSpace *nspace; @@ -1732,7 +1723,7 @@ static void CDecl_DataDeclarator(DeclInfo *declinfo, short access, Boolean flag) if (IS_TYPE_CLASS(declinfo->thetype) && TYPE_CLASS(declinfo->thetype)->sominfo) CError_Error(CErrorStr288); if (!CanCreateObject(declinfo->thetype)) - declinfo->thetype = (Type *) &stsignedint; + declinfo->thetype = TYPE(&stsignedint); obj = CParser_NewGlobalDataObject(declinfo); obj->access = access; @@ -3131,11 +3122,11 @@ static void InlineFunctionObject(Object *obj, TypeClass *tclass) { void CDecl_ExtractClassExportFlags(DeclInfo *declinfo, UInt8 flags) { if (flags & CLASS_EFLAGS_INTERNAL) - declinfo->exportflags |= EXPORT_FLAGS_INTERNAL; + declinfo->exportflags = declinfo->exportflags | EXPORT_FLAGS_INTERNAL; if (flags & CLASS_EFLAGS_IMPORT) - declinfo->exportflags |= EXPORT_FLAGS_IMPORT; + declinfo->exportflags = declinfo->exportflags | EXPORT_FLAGS_IMPORT; if (flags & CLASS_EFLAGS_EXPORT) - declinfo->exportflags |= EXPORT_FLAGS_EXPORT; + declinfo->exportflags = declinfo->exportflags | EXPORT_FLAGS_EXPORT; } TypeMemberFunc *CDecl_MakeTypeMemberFunc(TypeFunc *tfunc, TypeClass *tclass, Boolean flag) { @@ -3164,7 +3155,7 @@ static void CDecl_MakeFunctionVirtual(TypeClass *tclass, Object *func) { func->datatype = DVFUNC; } -static void CDecl_AddFunctionMember(DeclE *decle, TypeClass *tclass, DeclInfo *declinfo, short access, Boolean flag1, Boolean flag2, Boolean flag3, Boolean flag4) { +static void CDecl_AddFunctionMember(DeclE *decle, TypeClass *tclass, DeclInfo *declinfo, AccessType access, Boolean flag1, Boolean flag2, Boolean flag3, Boolean flag4) { NameSpaceObjectList *list; // r20 Object *obj; // also r20 TypeMemberFunc *tfunc; // r19 @@ -3228,7 +3219,7 @@ static void CDecl_AddFunctionMember(DeclE *decle, TypeClass *tclass, DeclInfo *d if (flag2) { tfunc->flags |= FUNC_FLAGS_40; - tclass->flags |= CLASS_FLAGS_40; + tclass->flags = tclass->flags | CLASS_FLAGS_40; } if (r31) { @@ -3241,7 +3232,7 @@ static void CDecl_AddFunctionMember(DeclE *decle, TypeClass *tclass, DeclInfo *d if (!CInt64_IsZero(&tkintconst)) CError_Error(CErrorStr121); tfunc->flags |= FUNC_FLAGS_8; - tclass->flags |= CLASS_FLAGS_ABSTRACT; + tclass->flags = tclass->flags | CLASS_FLAGS_ABSTRACT; tk = lex(); } else { CError_Error(CErrorStr121); @@ -3258,7 +3249,7 @@ static void CDecl_AddFunctionMember(DeclE *decle, TypeClass *tclass, DeclInfo *d CBrowse_AddClassMemberFunction(obj, CPrep_BrowserTokenOffset(&member_fileoffset) + 1, CPrep_BrowserFileOffset()); } -static Boolean CDecl_IsAccessDeclaration(TypeClass *tclass, short access) { +static Boolean CDecl_IsAccessDeclaration(TypeClass *tclass, AccessType access) { SInt32 state; Boolean flag; @@ -3383,7 +3374,7 @@ static void CDecl_ParseFriendDecl(TypeClass *tclass) { Object *obj; NameSpace *nspace; - is_templ = (tclass->flags & CLASS_FLAGS_100) ? 1 : 0; + is_templ = (tclass->flags & CLASS_FLAGS_100) != 0; r27 = (tk == TK_CLASS || tk == TK_STRUCT || tk == TK_UNION); memclrw(&declinfo, sizeof(DeclInfo)); @@ -3469,7 +3460,7 @@ static void CDecl_ParseFriendDecl(TypeClass *tclass) { CError_Error(CErrorStr123); } -static ObjMemberVar *CDecl_InstanceDataDeclarator(DeclE *decle, TypeClass *tclass, Type *type, UInt32 qual, HashNameNode *name, short access) { +static ObjMemberVar *CDecl_InstanceDataDeclarator(DeclE *decle, TypeClass *tclass, Type *type, UInt32 qual, HashNameNode *name, AccessType access) { NameSpaceObjectList *list; ObjMemberVar *ivar; ObjMemberVar *scan; @@ -3533,12 +3524,7 @@ void CDecl_CheckCtorIntegrity(FuncArg *args, TypeClass *tclass) { } static void CDecl_ParseClassMembers(DeclE *decle, TypeClass *tclass, short mode) { - short access; - UInt32 r22; - UInt32 r21; - UInt8 r20; - Boolean r19; - UInt8 r18; + AccessType access; Boolean r17; BigDeclInfo bde; DeclInfo declinfo; @@ -3546,18 +3532,18 @@ static void CDecl_ParseClassMembers(DeclE *decle, TypeClass *tclass, short mode) ObjMemberVar *ivar; ObjMemberVar *scanivar; Type *tmptype; + UInt32 r22; + UInt32 r21; + UInt8 r20; + UInt8 r18; + Boolean r19; short t; r17 = (tclass->flags & CLASS_FLAGS_100) && TEMPL_CLASS(tclass)->pspec_owner; memclrw(&bde, sizeof(BigDeclInfo)); - if (mode == CLASS_MODE_2) - access = ACCESSPRIVATE; - else - access = ACCESSPUBLIC; + access = (mode == CLASS_MODE_2) ? ACCESSPRIVATE : ACCESSPUBLIC; global_access = access; - //global_access = (mode == CLASS_MODE_2) ? ACCESSPRIVATE : ACCESSPUBLIC; - //access = (mode == CLASS_MODE_2) ? ACCESSPRIVATE : ACCESSPUBLIC; restart: while (tk != '}') { @@ -3967,7 +3953,7 @@ void CDecl_MakeVBaseList(TypeClass *tclass) { SInt32 offset; if (copts.vbase_ctor_offset) - tclass->flags |= CLASS_FLAGS_8000; + tclass->flags = tclass->flags | CLASS_FLAGS_8000; for (base = tclass->bases, offset = tclass->size; base; base = base->next) { for (vbase = base->base->vbases; vbase; vbase = vbase->next) { @@ -4002,7 +3988,7 @@ Boolean CDecl_CheckNewBase(TypeClass *tclass, TypeClass *baseclass, Boolean is_v CError_Error(CErrorStr191); return 0; } - tclass->flags |= CLASS_FLAGS_10; + tclass->flags = tclass->flags | CLASS_FLAGS_10; } if (baseclass->flags & CLASS_FLAGS_1) { @@ -4010,7 +3996,7 @@ Boolean CDecl_CheckNewBase(TypeClass *tclass, TypeClass *baseclass, Boolean is_v CError_Error(CErrorStr191); return 0; } - tclass->flags |= CLASS_FLAGS_1; + tclass->flags = tclass->flags | CLASS_FLAGS_1; } if (baseclass->sominfo) { @@ -4039,21 +4025,21 @@ Boolean CDecl_CheckNewBase(TypeClass *tclass, TypeClass *baseclass, Boolean is_v } if (baseclass->flags & CLASS_FLAGS_2000) - tclass->flags |= CLASS_FLAGS_2000; + tclass->flags = tclass->flags | CLASS_FLAGS_2000; if (baseclass->flags & CLASS_FLAGS_40) - tclass->flags |= CLASS_FLAGS_40; + tclass->flags = tclass->flags | CLASS_FLAGS_40; if (baseclass->flags & CLASS_FLAGS_20) - tclass->flags |= CLASS_FLAGS_20; + tclass->flags = tclass->flags | CLASS_FLAGS_20; if (is_virtual) - tclass->flags |= CLASS_FLAGS_20; + tclass->flags = tclass->flags | CLASS_FLAGS_20; return 1; } static void CDecl_ParseBaseClassList(TypeClass *tclass, short mode, Boolean is_templ) { Boolean is_virtual; - short access; + AccessType access; CScopeParseResult pr; ObjType *inherited_type; ClassList *base; @@ -4113,7 +4099,7 @@ static void CDecl_ParseBaseClassList(TypeClass *tclass, short mode, Boolean is_t CParser_CheckTemplateClassUsage(TEMPL_CLASS(pr.x8), 1)) { CTemplClass_RegisterBaseClass(TEMPL_CLASS(tclass), pr.x8, access, is_virtual); if (is_virtual) - tclass->flags |= CLASS_FLAGS_20; + tclass->flags = tclass->flags | CLASS_FLAGS_20; } continue; } @@ -4135,12 +4121,12 @@ static void CDecl_ParseBaseClassList(TypeClass *tclass, short mode, Boolean is_t if (!strcmp(tkidentifier->name, "SingleObject") || !strcmp(tkidentifier->name, "SingleInheritance")) { if (tclass->bases) CError_Error(CErrorStr191); - tclass->flags |= CLASS_FLAGS_10; + tclass->flags = tclass->flags | CLASS_FLAGS_10; tk = lex(); break; } if (!strcmp(tkidentifier->name, "__comobject")) { - tclass->flags |= CLASS_FLAGS_2000; + tclass->flags = tclass->flags | CLASS_FLAGS_2000; tk = lex(); break; } @@ -4190,7 +4176,7 @@ static void CDecl_ParseBaseClassList(TypeClass *tclass, short mode, Boolean is_t } } -static short getaccesstype(AccessType a, AccessType b, AccessType c) { +static AccessType getaccesstype(AccessType a, AccessType b, AccessType c) { if (a == ACCESSNONE || b == ACCESSNONE || b == ACCESSPRIVATE) return ACCESSNONE; @@ -4220,14 +4206,14 @@ static void CDecl_AddDefArgConstructor(TypeClass *tclass) { // empty } -static void CDecl_AddMemberFunctionObject(TypeClass *tclass, HashNameNode *name, TypeMemberFunc *tmeth, short access) { +static void CDecl_AddMemberFunctionObject(TypeClass *tclass, HashNameNode *name, TypeMemberFunc *tmeth, AccessType access) { Object *obj = CParser_NewCompilerDefFunctionObject(); obj->name = name; obj->type = TYPE(tmeth); obj->qual = Q_80000; obj->access = access; obj->nspace = tclass->nspace; - obj->qual |= Q_INLINE; + obj->qual = obj->qual | Q_INLINE; CScope_AddObject(tclass->nspace, obj->name, OBJ_BASE(obj)); } @@ -4299,7 +4285,7 @@ static void CDecl_AddDefaultCopyConstructor(DeclE *decle, TypeClass *tclass) { ClassList *base; ObjMemberVar *ivar; Object *obj; - short access; + AccessType access; Boolean has_copyctor; Boolean is_const; FuncArg *arg; @@ -4377,7 +4363,7 @@ static void CDecl_AddDefaultAssignmentOperator(DeclE *decle, TypeClass *tclass) ClassList *base; ObjMemberVar *ivar; Object *obj; - short access; + AccessType access; Boolean is_const; Boolean has_ass; DeclInfo declinfo; @@ -4442,7 +4428,7 @@ static void CDecl_AddDefaultDestructor(DeclE *decle, TypeClass *tclass) { ClassList *base; ObjMemberVar *ivar; Object *obj; - short access; + AccessType access; Boolean has_dtor; Boolean is_virtual; DeclInfo declinfo; @@ -4662,11 +4648,11 @@ void CDecl_ParseClassDeclSpec(UInt8 *declspec) { memclrw(&declinfo, sizeof(DeclInfo)); CParser_ParseDeclSpec(&declinfo, 1); if (declinfo.exportflags & EXPORT_FLAGS_INTERNAL) - *declspec |= CLASS_EFLAGS_INTERNAL; + *declspec = *declspec | CLASS_EFLAGS_INTERNAL; if (declinfo.exportflags & EXPORT_FLAGS_IMPORT) - *declspec |= CLASS_EFLAGS_IMPORT; + *declspec = *declspec | CLASS_EFLAGS_IMPORT; if (declinfo.exportflags & EXPORT_FLAGS_EXPORT) - *declspec |= CLASS_EFLAGS_EXPORT; + *declspec = *declspec | CLASS_EFLAGS_EXPORT; if ((tk = lex()) != ')') CError_Error(CErrorStr115); else @@ -4802,7 +4788,7 @@ void CDecl_ParseClass(DeclInfo *declinfo, short mode, Boolean flag1, UInt8 class } } - is_templ = (tclass->flags & CLASS_FLAGS_100) ? 1 : 0; + is_templ = (tclass->flags & CLASS_FLAGS_100) != 0; if (tclass->flags & CLASS_FLAGS_800) { TEMPL_CLASS_INST(tclass)->is_instantiated = 1; if (!declinfo->x28) @@ -4811,7 +4797,7 @@ void CDecl_ParseClass(DeclInfo *declinfo, short mode, Boolean flag1, UInt8 class CError_ASSERT(6853, copts.structalignment >= 0 && copts.structalignment <= 14); - tclass->eflags |= (UInt8) ((copts.structalignment + 1) << 4); + tclass->eflags = tclass->eflags | (((copts.structalignment + 1) << 4) & 0xF0); if (tk == ':') CDecl_ParseBaseClassList(tclass, mode, is_templ); -- cgit v1.2.3