Created
May 26, 2017 10:27
-
-
Save ktopouzi/c445566219bf7f3aa79d703c2ea837b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public override TypePrinterResult VisitFieldDecl(Field field) | |
{ | |
var safeIdentifier = SafeIdentifier(field.Name); | |
PushMarshalKind(MarshalKind.NativeField); | |
var fieldTypePrinted = field.QualifiedType.CSharpType(this); | |
PopMarshalKind(); | |
var fieldType = field.QualifiedType.Type.Desugar().IsAddress() ? | |
CSharpTypePrinter.IntPtrType : fieldTypePrinted.Type; | |
var fieldName = safeIdentifier; | |
if (!string.IsNullOrWhiteSpace(fieldTypePrinted.NameSuffix)) | |
fieldName += fieldTypePrinted.NameSuffix; | |
TypePrinterResult returnTypePrinter = new TypePrinterResult(); | |
returnTypePrinter.NameSuffix =fieldType; | |
returnTypePrinter.Type = fieldName; | |
return returnTypePrinter; | |
} | |
============================================================================================= | |
Declaration decl; | |
field.QualifiedType.Type.TryGetDeclaration(out decl); | |
var arrayType = field.QualifiedType.Type.Desugar() as ArrayType; | |
var coreType = field.QualifiedType.Type.Desugar(); | |
if (arrayType != null && arrayType.SizeType == ArrayType.ArraySize.Constant) | |
coreType = arrayType.Type.Desugar(); | |
// we do not support the primitives below yet because their representation in C# is problematic | |
if (coreType.IsPrimitiveType(PrimitiveType.Int128) || | |
coreType.IsPrimitiveType(PrimitiveType.UInt128) || | |
coreType.IsPrimitiveType(PrimitiveType.Half)) | |
return; | |
var safeIdentifier = SafeIdentifier(field.Name); | |
//if (safeIdentifier == "longDouble") | |
//{ | |
TypePrinterResult retType = TypePrinter.VisitFieldDecl(new Field { Name = field.Name, QualifiedType = field.QualifiedType }); | |
//WriteLine(retType.ToString()); | |
System.Diagnostics.Debugger.Break(); | |
//} | |
if (safeIdentifier.All(c => c.Equals('_'))) | |
{ | |
safeIdentifier = SafeIdentifier(field.Name); | |
} | |
PushBlock(BlockKind.Field); | |
if (!Options.GenerateSequentialLayout || @class.IsUnion) | |
WriteLine($"[FieldOffset({field.Offset})]"); | |
//TypePrinter.PushMarshalKind(MarshalKind.NativeField); | |
//var fieldTypePrinted = field.QualifiedType.CSharpType(TypePrinter); | |
//TypePrinter.PopMarshalKind(); | |
//var fieldType = field.QualifiedType.Type.Desugar().IsAddress() ? | |
// CSharpTypePrinter.IntPtrType : fieldTypePrinted.Type; | |
//var fieldName = safeIdentifier; | |
//if (!string.IsNullOrWhiteSpace(fieldTypePrinted.NameSuffix)) | |
// fieldName += fieldTypePrinted.NameSuffix; | |
var access = decl != null && !decl.IsGenerated ? "internal" : "public"; | |
if (field.Expression != null) | |
{ | |
var fieldValuePrinted = field.Expression.CSharpValue(ExpressionPrinter); | |
Write($"{access} {retType.NameSuffix} {retType.Type} = {fieldValuePrinted};"); | |
} | |
else | |
{ | |
Write($"{access} {retType.NameSuffix} {retType.Type};"); | |
} | |
PopBlock(NewLineKind.BeforeNextBlock); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment