Macro: REGISTER_FUNCTION

Module location: FMAC line 11649 (view source)

Changes: Check for Global error (used to check !1) Check for Object access name error Check that the name is not a global name

  #IFDEF UI.EXISTS
  #ELSE
    USE UI
  #ENDIF

  #IF ( (!Zl & 1)=0)
    #IFSAME FN$!1  __F__
      #ERROR DFERR_COMP_ILLEGAL_METHOD_DEFINTION !1 is an internal function name
    #ENDIF
  #ENDIF

  #IFSAME RETURNS !2 !3 !4 !5 !6 !7 !8 !9
  #ELSE
    #ERROR DFERR_COMP_INVALID_METHOD_SYNTAX MISSING KEYWORD RETURNS ON FUNCTION DECLARATION
  #ENDIF

  #IFSAME !2 GLOBAL
    #ERROR DFERR_COMP_ILLEGAL_METHOD_DEFINTION GLOBAL FUNCTIONS CANNOT BE REGISTERED
  #ELSE
    // Check if non-mangled symbol is already defined.
    // If it is, it might be an object name...error
    //           also make sure new function is not an overload..error
    #IFDEF GET_!1

      #IF (GET_!1<0)
        #ERROR DFERR_COMP_ILLEGAL_METHOD_DEFINTION !1 is already defined as a global function
      #ENDIF

      #IF (GET_!1>$40000000)
        #ERROR DFERR_COMP_ILLEGAL_METHOD_DEFINTION !1 is already defined as an object
      #ENDIF

      #IFDEF MANGLE_NAMES
        #IFSAME OVERLOADED !2 !3 !4 !5 !6 !7 !8 !9
          #ERROR DFERR_COMP_ILLEGAL_METHOD_DEFINTION This Method Was Previously Defined As Non-Overloaded
        #ENDIF
      #ENDIF
      // Validate the argument list.
      CHECK$METHOD$ARGUMENT$LIST  !2 !3 !4 !5 !6 !7 !8 !9
      // We will get more chance of matching fixups (and creating fewer errors) if we just register the function anyway.
      // The parameter list could generate the right name and if it does later fixups will resolve correctly without error.
      // It's possible that the list changes the mangled name. If it does, when the function is fixed, fixup errors may
      // appear. They can be fixed then.
      MESSAGE$ADDRESS GET_!1            // Generate the constant for message identifier. Message$Address checks if it already exists.
    #ELSE
      // Verify that the argument list is syntactically correct.
      CHECK$METHOD$ARGUMENT$LIST  !2 !3 !4 !5 !6 !7 !8 !9

      // Create the constant identifier for the message if it's not already defined.
      #IFNDEF MANGLE_NAMES
        MESSAGE$ADDRESS GET_!1
      #ELSE
        #IFSAME OVERLOADED !2 !3 !4 !5 !6 !7 !8 !9
          // we don't support Byref with overloading
          #IFSAME BYREF !2 !3 !4 !5 !6 !7 !8 !9
            #ERROR DFERR_COMP_ILLEGAL_METHOD_DEFINTION "BYREF not allowed in overloaded methods"
          #ENDIF
          #MARG GET_!1 !2 !3 !4 !5 !6 !7 !8 !9    // Genearte the mangled symbol.
          MESSAGE$ADDRESS !?                      // Generate the message identifer.
          // if this is the first time we've defined this, create overloaded symbol
          #IFNDEF GET_!1_OVERLOADED
            #REPLACE GET_!1_OVERLOADED  |CI1
          #ENDIF
        #ELSE
          // We are defining a non-overload function. Make sure we have not already
          // defined it as overloaded
          #IFDEF GET_!1_OVERLOADED
            #ERROR DFERR_COMP_ILLEGAL_METHOD_DEFINTION !1 is already defined as an overloaded function
          #ELSE
            MESSAGE$ADDRESS GET_!1
          #ENDIF
        #ENDIF
      #ENDIF
    #ENDIF

    // Register the function here.
    #IFNDEF MANGLE_NAMES
      #IFSAME !2 FOR
        #FREG GET_!1 !4 !5 !6 !7 !8 !9
      #ELSE
        #FREG GET_!1 !2 !3 !4 !5 !6 !7 !8 !9
      #ENDIF
    #ELSE
      #IFSAME OVERLOADED !2 !3 !4 !5 !6 !7 !8 !9
        #IFSAME !2 FOR
          #FREG !? !4 !5 !6 !7 !8 !9
        #ELSE
          #FREG !? !2 !3 !4 !5 !6 !7 !8 !9
        #ENDIF
      #ELSE
        #IFSAME !2 FOR
          #FREG GET_!1 !4 !5 !6 !7 !8 !9
        #ELSE
          #FREG GET_!1 !2 !3 !4 !5 !6 !7 !8 !9
        #ENDIF
      #ENDIF
    #ENDIF

  #ENDIF   // Not a global