public override void WriteTo(CCodeWriterBase c) { c.TextSpanNewLine("inline static GC_descr __get_type_descriptor()"); c.OpenBlock(); c.TextSpan("typedef"); c.WhiteSpace(); c.WriteType(this.Type, true, true, true); c.WhiteSpace(); c.TextSpanNewLine("__type;"); c.TextSpanNewLine("GC_word bitmap[GC_BITMAP_SIZE(__type)] = {0};"); // set fields foreach (var field in this.Type.EnumPossibleReferenceFields()) { c.TextSpan("GC_set_bit(bitmap, GC_WORD_OFFSET(__type,"); c.WhiteSpace(); // TODO: fix it, replace with "base" type as generic types causing issues ////c.WriteFieldAccessAsStaticField(field); c.WriteName(field); c.TextSpanNewLine("));"); } c.TextSpanNewLine("return GC_make_descriptor(bitmap, GC_WORD_LEN(__type));"); c.EndBlock(); c.Separate(); }
internal override void WriteTo(CCodeWriterBase c) { c.TextSpan("if"); c.WhiteSpace(); c.TextSpan("("); if (!this.JumpIfTrue) { c.TextSpan("!"); c.WriteWrappedExpressionIfNeeded(this.Condition); } else { this.Condition.WriteTo(c); } c.TextSpan(")"); c.NewLine(); c.OpenBlock(); new GotoStatement { Label = this.Label }.WriteTo(c); c.EndBlock(); c.Separate(); }
public override void WriteTo(CCodeWriterBase c) { c.Separate(); c.TextSpan(string.Format("// adapter: {0}", Method)); c.NewLine(); foreach (var statement in this.typeDefs) { statement.WriteTo(c); } var namedTypeSymbol = (INamedTypeSymbol)this.type; if (namedTypeSymbol.IsGenericType) { c.WriteTemplateDeclaration(namedTypeSymbol); c.NewLine(); } c.WriteMethodReturn(Method, true); c.WriteMethodNamespace(namedTypeSymbol); c.WriteMethodName(Method, false, interfaceWrapperMethodSpecialCase: true); c.WriteMethodParameters(Method, true, MethodBodyOpt != null); if (MethodBodyOpt == null) { c.EndStatement(); } else { MethodBodyOpt.WriteTo(c); } }
internal override void WriteTo(CCodeWriterBase c) { if (this.Statements != null) { c.WriteBlockOrStatementsAsBlock(this.Statements); } else { base.WriteTo(c); } if (!this.NoSeparation) { // No normal ending of Statement as we do not need extra ; c.Separate(); } }
public override void WriteTo(CCodeWriterBase c) { c.TextSpan("void* operator new (size_t _size"); if (this.withExtraParams) { c.TextSpan(", int32_t _customSize"); } if (this.debugVersion) { c.TextSpan(", const char* _file, int _line"); } c.TextSpan(")"); MethodBodyOpt.WriteTo(c); c.Separate(); }
public override void WriteTo(CCodeWriterBase c) { CCodeWriterBase.SetLocalObjectIDGenerator(); c.Separate(); c.TextSpanNewLine(string.Format("// Method : {0}", this.Method.ToDisplayString())); c.WriteMethodDeclaration(this.Method, false); if (this.MethodBodyOpt != null) { this.MethodBodyOpt.WriteTo(c); } else { c.WriteMethodBody(this.BoundBody, this.Method); } }
internal override void WriteTo(CCodeWriterBase c) { if (this.FinallyBlockOpt != null) { var block = this.FinallyBlockOpt as Block; if (block != null) { block.SuppressNewLineAtEnd = true; } c.OpenBlock(); c.TextSpan("Finally"); c.WhiteSpace(); c.TextSpan("__finally_block"); c.TextSpan("("); new LambdaExpression() { Statements = block }.WriteTo(c); c.TextSpan(");"); c.NewLine(); } if (this.catchBlocks.Any()) { c.TextSpan("try"); } c.NewLine(); c.WriteBlockOrStatementsAsBlock(this.TryBlock); foreach (var catchBlock in this.catchBlocks) { catchBlock.WriteTo(c); } if (this.FinallyBlockOpt != null) { c.EndBlock(); } c.Separate(); }
internal override void WriteTo(CCodeWriterBase c) { if (this.Locals.Count > 0) { c.OpenBlock(); foreach (var statement in this.Locals) { statement.WriteTo(c); } } var block = this.Initialization as Block; if (block != null) { var any = false; foreach (var initializationItem in block.Statements) { if (any) { c.TextSpan(","); c.WhiteSpace(); } PrintStatementAsExpression(c, initializationItem); any = true; } } else { this.Initialization.WriteTo(c); } this.TryStatement.WriteTo(c); if (this.Locals.Count > 0) { c.EndBlock(); // No normal ending of Statement as we do not need extra ; c.Separate(); } }
public override void WriteTo(CCodeWriterBase c) { c.TextSpan("class"); c.WhiteSpace(); c.WriteTypeName((INamedTypeSymbol)this.Type); c.OpenBlock(); c.DecrementIndent(); c.TextSpanNewLine("public:"); c.IncrementIndent(); foreach (var declarations in this.Declarations) { declarations.WriteTo(c); } c.EndBlock(); c.Separate(); }
internal override void WriteTo(CCodeWriterBase c) { c.TextSpan("if"); c.WhiteSpace(); c.TextSpan("("); this.Condition.WriteTo(c); c.TextSpan(")"); c.NewLine(); c.WriteBlockOrStatementsAsBlock(this.IfStatements); if (this.ElseStatementsOpt != null) { c.TextSpan("else"); c.NewLine(); c.WriteBlockOrStatementsAsBlock(this.ElseStatementsOpt); } c.Separate(); // No normal ending of Statement as we do not need extra ; }
internal override void WriteTo(CCodeWriterBase c) { Local localCase = null; if (this.stringEquality != null) { c.OpenBlock(); var localImpl = new LocalImpl { Name = "__SwitchExpression", Type = this.expression.Type }; var local = new Local { LocalSymbol = localImpl }; var localImplCase = new LocalImpl { Name = "__SwitchCase", Type = new TypeImpl { SpecialType = SpecialType.System_Int32 } }; localCase = new Local { LocalSymbol = localImplCase }; new VariableDeclaration { Statements = { new ExpressionStatement { Expression = new AssignmentOperator { TypeDeclaration = true, Type = new TypeImpl { SpecialType = SpecialType.System_Int32 }, Left = localCase, Right = new Literal{ Value = ConstantValue.Create(0) } } } } }.WriteTo(c); new VariableDeclaration { Statements = { new ExpressionStatement { Expression = new AssignmentOperator { TypeDeclaration = true, Type = new TypeImpl { SpecialType = SpecialType.System_String }, Left = local, Right = this.expression } } } }.WriteTo(c); // first if IfStatement first = null; IfStatement last = null; var caseIndex = 0; foreach (var switchSection in this.switchCases) { foreach (var label in switchSection.Labels) { if (label.Value == null) { // default case; continue; } caseIndex++; // compare var callEqual = new Call() { Method = this.stringEquality }; callEqual.Arguments.Add(local); callEqual.Arguments.Add(new Literal { Value = label.Value }); // set value var setExpr = new ExpressionStatement { Expression = new AssignmentOperator { Left = localCase, Right = new Literal { Value = ConstantValue.Create(caseIndex) } } }; var ifStatement = new IfStatement { Condition = callEqual, IfStatements = setExpr }; first = first ?? ifStatement; if (last != null) { last.ElseStatementsOpt = ifStatement; } last = ifStatement; // remap case value label.Value = ConstantValue.Create(caseIndex); } } if (first != null) { first.WriteTo(c); } c.Separate(); } foreach (var statement in this.statements) { statement.WriteTo(c); } var generateDefaultLabel = this.isNullableType; if (this.isNullableType) { var nullCase = this.switchCases.FirstOrDefault(sc => sc.Labels.Any(l => l.Value != null && l.Value.IsNull)); if (nullCase != null) { generateDefaultLabel = false; } var nullCaseOrDefault = nullCase ?? this.switchCases.FirstOrDefault(sc => sc.Labels.Any(l => l.Value == null)); if (nullCaseOrDefault != null) { var effectiveExpression = this.expression; var callExpression = this.expression as Call; if (callExpression != null) { effectiveExpression = new UnaryOperator { OperatorKind = UnaryOperatorKind.LogicalNegation, Operand = new Call { ReceiverOpt = callExpression.ReceiverOpt, Method = new MethodImpl { Name = "get_HasValue", Parameters = ImmutableArray <IParameterSymbol> .Empty } } }; } // we need to insert nullable goto; var ifStatement = new IfStatement { Condition = effectiveExpression, IfStatements = new GotoStatement { Label = nullCaseOrDefault.Labels.First(l => l.Value == null || l.Value.IsNull) } }; ifStatement.WriteTo(c); } } c.TextSpan("switch"); c.WhiteSpace(); c.TextSpan("("); if (this.stringEquality != null) { localCase.WriteTo(c); } else { this.expression.WriteTo(c); } c.TextSpan(")"); c.NewLine(); c.OpenBlock(); foreach (var switchSection in this.switchCases) { if (!generateDefaultLabel && switchSection.Labels.Any(l => l.Value == null)) { switchSection.IsNullableType = false; } switchSection.WriteTo(c); } c.EndBlock(); if (this.stringEquality != null) { c.EndBlock(); } c.Separate(); }
internal override void WriteTo(CCodeWriterBase c) { Local localCase = null; if (this.stringEquality != null) { c.OpenBlock(); var localImpl = new LocalImpl { Name = "__SwitchExpression", Type = this.expression.Type }; var local = new Local { LocalSymbol = localImpl }; var localImplCase = new LocalImpl { Name = "__SwitchCase", Type = new TypeImpl { SpecialType = SpecialType.System_Int32 } }; localCase = new Local { LocalSymbol = localImplCase }; new VariableDeclaration { Local = localCase }.WriteTo(c); new VariableDeclaration { Local = local }.WriteTo(c); // first if IfStatement first = null; IfStatement last = null; var caseIndex = 0; foreach (var switchSection in this.switchCases) { foreach (var label in switchSection.Labels) { if (label.Value == null) { // default case; continue; } caseIndex++; // compare var callEqual = new Call() { Method = this.stringEquality }; callEqual.Arguments.Add(local); callEqual.Arguments.Add(new Literal { Value = label.Value }); // set value var setExpr = new ExpressionStatement { Expression = new AssignmentOperator { Left = localCase, Right = new Literal { Value = ConstantValue.Create(caseIndex) } } }; var ifStatement = new IfStatement { Condition = new BinaryOperator { OperatorKind = BinaryOperatorKind.Equal, Left = new Literal { Value = ConstantValue.Create(0) }, Right = callEqual }, IfStatements = setExpr }; first = first ?? ifStatement; if (last != null) { last.ElseStatementsOpt = ifStatement; } last = ifStatement; // remap case value label.Value = ConstantValue.Create(caseIndex); } } if (first != null) { first.WriteTo(c); } c.Separate(); } foreach (var statement in this.statements) { statement.WriteTo(c); } c.TextSpan("switch"); c.WhiteSpace(); c.TextSpan("("); if (this.stringEquality != null) { localCase.WriteTo(c); } else { this.expression.WriteTo(c); } c.TextSpan(")"); c.NewLine(); c.OpenBlock(); foreach (var switchSection in this.switchCases) { switchSection.WriteTo(c); } c.EndBlock(); if (this.stringEquality != null) { c.EndBlock(); } c.Separate(); }