Jelajahi Sumber

Enum fixes, small reflection fixes

Brian Fiete 5 tahun lalu
induk
melakukan
dffde00a6a

+ 1 - 1
BeefLibs/corlib/src/Attribute.bf

@@ -334,7 +334,7 @@ namespace System
 
 		}
 
-		public this(String error, bool isError)
+		public this(String message, bool isError)
 		{
 
 		}

+ 2 - 2
BeefLibs/corlib/src/Reflection/TypeInstance.bf

@@ -39,7 +39,7 @@ namespace System.Reflection
 {
 	extension TypeInstance
 	{
-		public override FieldInfo? GetField(String fieldName)
+		public override Result<FieldInfo> GetField(String fieldName)
 		{
 		    for (int32 i = 0; i < mFieldDataCount; i++)
 		    {
@@ -47,7 +47,7 @@ namespace System.Reflection
 		        if (fieldData.mName == fieldName)
 		            return FieldInfo(this, fieldData);
 		    }
-		    return null;
+		    return .Err;
 		}
 
 		public override FieldInfo.Enumerator GetFields(BindingFlags bindingFlags = cDefaultLookup)

+ 22 - 4
BeefLibs/corlib/src/Type.bf

@@ -349,6 +349,24 @@ namespace System
 			}
 		}
 
+		public virtual int32 MinValue
+		{
+			[Error("This property can only be accessed directly from a typeof() expression")]
+			get
+			{
+				return 0;
+			}
+		}
+
+		public virtual int32 MaxValue
+		{
+			[Error("This property can only be accessed directly from a typeof() expression")]
+			get
+			{
+				return 0;
+			}
+		}
+
         public int32 GetTypeId()
         {
             return (int32)mTypeId;
@@ -425,9 +443,9 @@ namespace System
             return type == this;
         }
 
-		public virtual FieldInfo? GetField(String fieldName)
+		public virtual Result<FieldInfo> GetField(String fieldName)
 		{
-		    return null;
+		    return .Err;
 		}
 
 		public virtual FieldInfo.Enumerator GetFields(BindingFlags bindingFlags = cDefaultLookup)
@@ -665,7 +683,7 @@ namespace System.Reflection
             strBuffer.Append(mName);
         }
 
-		public override FieldInfo? GetField(String fieldName)
+		public override Result<FieldInfo> GetField(String fieldName)
 		{
 		    for (int32 i = 0; i < mFieldDataCount; i++)
 		    {
@@ -673,7 +691,7 @@ namespace System.Reflection
 		        if (fieldData.mName == fieldName)
 		            return FieldInfo(this, fieldData);
 		    }
-		    return null;
+		    return .Err;
 		}
 
 		public override FieldInfo.Enumerator GetFields(BindingFlags bindingFlags = cDefaultLookup)

+ 2 - 2
BeefySysLib/platform/win/WinBFApp.cpp

@@ -132,9 +132,9 @@ WinBFWindow::WinBFWindow(BFWindow* parent, const StringImpl& title, int x, int y
 		::SystemParametersInfo(SPI_GETWORKAREA, NULL, &desktopRect, NULL);		
 
 		if (x + width >= desktopRect.right)
-			x = BF_MAX((int)desktopRect.left, requestedX - width);
+			x = BF_MAX((int)desktopRect.left, desktopRect.right - width);
 		if (y + height >= desktopRect.bottom)
-			y = BF_MAX((int)desktopRect.top, requestedY - height);
+			y = BF_MAX((int)desktopRect.top, desktopRect.bottom - height);
 	}
 	
 	mFlags = windowFlags;

+ 52 - 7
IDE/mintest/minlib/src/System/Internal.bf

@@ -51,8 +51,10 @@ namespace System
 		public static extern void ObjectDynCheck(Object obj, int32 typeId, bool allowNull);
 		public static extern void ObjectDynCheckFailed(Object obj, int32 typeId);
 		public static extern void Dbg_ObjectCreated(Object obj, int size, ClassVData* classVData);
+		public static extern void Dbg_ObjectCreatedEx(Object obj, int size, ClassVData* classVData);
 		public static extern void Dbg_ObjectAllocated(Object obj, int size, ClassVData* classVData);
-		public static extern int Dbg_PrepareStackTrace(int maxDepth);
+		public static extern void Dbg_ObjectAllocatedEx(Object obj, int size, ClassVData* classVData);
+		public static extern int Dbg_PrepareStackTrace(int baseAllocSize, int maxStackTraceDepth);
 		public static extern void Dbg_ObjectStackInit(Object object, ClassVData* classVData);
 		public static extern Object Dbg_ObjectAlloc(TypeInstance typeInst, int size);
 		public static extern Object Dbg_ObjectAlloc(ClassVData* classVData, int size, int align, int maxStackTraceDepth);
@@ -139,6 +141,8 @@ namespace System
         public static String[] CreateParamsArray()
 		{
 			char8* cmdLine = GetCommandLineArgs();
+			//Windows.MessageBoxA(default, scope String()..AppendF("CmdLine: {0}", StringView(cmdLine)), "HI", 0);
+
 			String[] strVals = null;
 			for (int pass = 0; pass < 2; pass++)
 			{
@@ -151,21 +155,40 @@ namespace System
 						var str = new String(len);
 						char8* outStart = str.Ptr;
 						char8* outPtr = outStart;
+						bool inQuote = false;
 
 						for (int i < len)
 						{
 							char8 c = cmdLine[idx + i];
-							if (c == '\"')
+
+							if (!inQuote)
 							{
-								if ((cmdLine[idx + i + 1] == '\"') &&
-									(cmdLine[idx + i + 2] == '\"'))
+								if (c == '"')
 								{
-									*(outPtr++) = '\"';
-									i += 2;
+									inQuote = true;
 									continue;
 								}
-								continue;
 							}
+							else
+							{
+								if (c == '^')
+								{
+									i++;
+									c = cmdLine[idx + i];
+								}
+								else if (c == '\"')
+								{
+									if (cmdLine[idx + i + 1] == '\"')
+									{
+										*(outPtr++) = '\"';
+										i++;
+										continue;
+									}
+									inQuote = false;
+									continue;
+								}
+							}
+
 							*(outPtr++) = c;
 						}
 						str.[Friend]mLength = (.)(outPtr - outStart);
@@ -195,6 +218,10 @@ namespace System
 				    {
 				        if (firstCharIdx == -1)
 				            firstCharIdx = i;
+						if (c == '^')
+						{	
+							i++;
+						}
 				        if (c == '"')
 				            inQuote = !inQuote;
 				        else if ((inQuote) && (c == '\\'))
@@ -225,4 +252,22 @@ namespace System
         extern static this();
         extern static ~this();
     }
+
+	struct CRTAlloc
+	{
+		public void* Alloc(int size, int align)
+		{
+			return Internal.StdMalloc(size);
+		}
+
+		public void Free(void* ptr)
+		{
+			Internal.StdFree(ptr);
+		}
+	}
+
+	static
+	{
+		public static CRTAlloc gCRTAlloc;
+	}
 }

+ 1 - 0
IDEHelper/COFF.cpp

@@ -994,6 +994,7 @@ void COFF::CvParseMembers(DbgType* parentType, int tagIdx, bool ipi)
 								parentType->mTypeParam = CvGetType(fieldTypeId);
 								if ((parentType->mBaseTypes.mHead != NULL) && (strcmp(parentType->mBaseTypes.mHead->mBaseType->mName, "System.Enum") == 0))
 									parentType->mTypeCode = DbgType_Enum;
+								break;
 							}
 						}
 

+ 1 - 5
IDEHelper/Compiler/BfContext.cpp

@@ -437,6 +437,7 @@ bool BfContext::ProcessWorkList(bool onlyReifiedTypes, bool onlyReifiedMethods)
 					continue;
 
 				auto methodSpecializationRequest = *workItemRef;
+
 				auto module = workItemRef->mFromModule;
 				workIdx = mMethodSpecializationWorkList.RemoveAt(workIdx);
 
@@ -2339,11 +2340,6 @@ void BfContext::QueueMethodSpecializations(BfTypeInstance* typeInst, bool checkS
 			return;
 	}
 
-	if ((module->mModuleName == "System_Array") && (!mCompiler->mIsResolveOnly))
-	{
-		NOP;
-	}
-
 	// Find any method specialization requests for types that are rebuilding, but from
 	//  modules that are NOT rebuilding to be sure we generate those.  Failure to do this
 	//  will cause a link error from an old module

+ 2 - 0
IDEHelper/Compiler/BfExprEvaluator.cpp

@@ -16163,6 +16163,7 @@ void BfExprEvaluator::PerformUnaryOperation_OnResult(BfExpression* unaryOpExpr,
 			MarkResultUsed();
 						
 			mModule->FixIntUnknown(mResult);
+			mModule->PopulateType(mResult.mType);
 			auto ptrType = mModule->CreatePointerType(mResult.mType);
 			if ((!CheckModifyResult(mResult, unaryOpExpr, "take address of")) || (mResult.mType->IsValuelessType()))
 			{
@@ -16194,6 +16195,7 @@ void BfExprEvaluator::PerformUnaryOperation_OnResult(BfExpression* unaryOpExpr,
 				return;
 			}
 
+			mModule->PopulateType(resolvedType);
 			if (resolvedType->IsValuelessType())			
 				mResult = BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), resolvedType, true);
 			else

+ 6 - 10
IDEHelper/Compiler/BfModule.cpp

@@ -1097,7 +1097,7 @@ void BfModule::EnsureIRBuilder(bool dbgVerifyCodeGen)
 			//  code as we walk the AST
 			//mBfIRBuilder->mDbgVerifyCodeGen = true;			
 			if (
-                (mModuleName == "IDE_ui_LaunchDialog")
+                (mModuleName == "Blurg")
 				//|| (mModuleName == "System_Internal")
 				//|| (mModuleName == "vdata")
 				//|| (mModuleName == "Hey_Dude_Bro_TestClass")
@@ -11036,7 +11036,7 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM
 		BF_ASSERT(instModule == mParentModule);
 	}
 	else if (instModule != this)
-	{
+	{		
 		if ((!mIsReified) && (instModule->mIsReified))
 		{
 			BF_ASSERT(!mCompiler->mIsResolveOnly);
@@ -11064,10 +11064,11 @@ BfModuleMethodInstance BfModule::GetMethodInstance(BfTypeInstance* typeInst, BfM
 				specializationRequest->mMethodDef = methodDef;
 				specializationRequest->mMethodGenericArguments = methodGenericArguments;
 				specializationRequest->mType = typeInst;				
+				specializationRequest->mFlags = flags;
 			}
 
 			auto defFlags = (BfGetMethodInstanceFlags)(flags & ~BfGetMethodInstanceFlag_ForceInline);
-
+			
 			// Not extern
 			// Create the instance in the proper module and then create a reference in this one
 			moduleMethodInst = instModule->GetMethodInstance(typeInst, methodDef, methodGenericArguments, defFlags, foreignType);
@@ -11769,12 +11770,7 @@ void BfModule::HadSlotCountDependency()
 }
 
 BfTypedValue BfModule::ReferenceStaticField(BfFieldInstance* fieldInstance)
-{	
-	if (fieldInstance->mResolvedType->IsVar())
-	{
-		NOP;
-	}
-
+{		
 	if (mIsScratchModule)
 	{
 		// Just fake it for the extern and unspecialized modules
@@ -19490,7 +19486,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool
 // 		CheckHotMethod(methodInstance, mangledName);
 
 	BfLogSysM("DoMethodDeclaration %s Module: %p Type: %p MethodInst: %p Reified: %d Unspecialized: %d IRFunction: %d MethodId:%llx\n", mangledName.c_str(), this, mCurTypeInstance, methodInstance, methodInstance->mIsReified, mCurTypeInstance->IsUnspecializedType(), methodInstance->mIRFunction.mId, methodInstance->mIdHash);
-
+	
 	SizedArray<BfIRMDNode, 8> diParams;	
 	diParams.push_back(mBfIRBuilder->DbgGetType(resolvedReturnType));			
 	

+ 7 - 2
IDEHelper/Compiler/BfResolvedTypeUtils.cpp

@@ -1867,9 +1867,14 @@ void BfTupleType::Finish()
 //////////////////////////////////////////////////////////////////////////
 
 BfType* BfBoxedType::GetModifiedElementType()
-{
+{	
 	if ((mBoxedFlags & BoxedFlags_StructPtr) != 0)
-		return mModule->CreatePointerType(mElementType);
+	{
+		auto module = mModule;
+		if (module == NULL)
+			module = mContext->mUnreifiedModule;		
+		return module->CreatePointerType(mElementType);		
+	}
 	return mElementType;
 }
 

+ 4 - 2
IDEHelper/DbgModule.cpp

@@ -1410,9 +1410,11 @@ DbgType* DbgType::GetPrimaryType()
 	{
 		if ((mCompileUnit != NULL) && 
 			((mCompileUnit->mLanguage == DbgLanguage_Beef) || (mTypeCode == DbgType_Namespace) || (mIsDeclaration)))
-		{
-			mPrimaryType = mCompileUnit->mDbgModule->GetPrimaryType(this);
+		{			
+			mPrimaryType = mCompileUnit->mDbgModule->GetPrimaryType(this);			
+			mPrimaryType->PopulateType();
 			mTypeCode = mPrimaryType->mTypeCode;
+			mTypeParam = mPrimaryType->mTypeParam;
 		}
 	}