mirror of
				https://github.com/Ed94/gencpp.git
				synced 2025-11-03 23:36:12 -08:00 
			
		
		
		
	Iterations on serialization improvements.
This commit is contained in:
		@@ -38,10 +38,13 @@ String AST::to_string()
 | 
			
		||||
 | 
			
		||||
		case Comment:
 | 
			
		||||
		{
 | 
			
		||||
			result.append("\n");
 | 
			
		||||
 | 
			
		||||
			static char line[MaxCommentLineLength];
 | 
			
		||||
 | 
			
		||||
			s32 left  = Content.length();
 | 
			
		||||
			s32 index = 0;
 | 
			
		||||
			s32 curr  = 0;
 | 
			
		||||
			do
 | 
			
		||||
			{
 | 
			
		||||
				s32 length = 0;
 | 
			
		||||
@@ -49,12 +52,17 @@ String AST::to_string()
 | 
			
		||||
				{
 | 
			
		||||
					length++;
 | 
			
		||||
					left--;
 | 
			
		||||
					index++;
 | 
			
		||||
				}
 | 
			
		||||
				index++;
 | 
			
		||||
 | 
			
		||||
				str_copy( line, Content, length );
 | 
			
		||||
				line[length] = '\0';
 | 
			
		||||
				str_copy( line, Content + curr, length );
 | 
			
		||||
				result.append_fmt( "//%.*s", length, line );
 | 
			
		||||
				mem_set( line, 0, MaxCommentLineLength);
 | 
			
		||||
 | 
			
		||||
				result.append_fmt( "// %s", line );
 | 
			
		||||
				length++;
 | 
			
		||||
				left--;
 | 
			
		||||
				curr = index;
 | 
			
		||||
			}
 | 
			
		||||
			while ( left--, left > 0 );
 | 
			
		||||
		}
 | 
			
		||||
@@ -115,7 +123,7 @@ String AST::to_string()
 | 
			
		||||
				result.append_fmt( "class %s\n{\n%s\n}", Name, Body->to_string() );
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if ( Parent && Parent->Type != ECode::Typedef )
 | 
			
		||||
			if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
 | 
			
		||||
				result.append(";");
 | 
			
		||||
		}
 | 
			
		||||
		break;
 | 
			
		||||
@@ -130,7 +138,7 @@ String AST::to_string()
 | 
			
		||||
 | 
			
		||||
			else result.append_fmt( "class %s", Name );
 | 
			
		||||
 | 
			
		||||
			if ( Parent && Parent->Type != ECode::Typedef )
 | 
			
		||||
			if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
 | 
			
		||||
				result.append(";");
 | 
			
		||||
		}
 | 
			
		||||
		break;
 | 
			
		||||
@@ -164,7 +172,7 @@ String AST::to_string()
 | 
			
		||||
				, Body->to_string()
 | 
			
		||||
			);
 | 
			
		||||
 | 
			
		||||
			if ( Parent && Parent->Type != ECode::Typedef )
 | 
			
		||||
			if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
 | 
			
		||||
				result.append(";");
 | 
			
		||||
		}
 | 
			
		||||
		break;
 | 
			
		||||
@@ -179,7 +187,7 @@ String AST::to_string()
 | 
			
		||||
 | 
			
		||||
			result.append_fmt( "enum %s : %s", Name, UnderlyingType->to_string() );
 | 
			
		||||
 | 
			
		||||
			if ( Parent && Parent->Type != ECode::Typedef )
 | 
			
		||||
			if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
 | 
			
		||||
				result.append(";");
 | 
			
		||||
		}
 | 
			
		||||
		break;
 | 
			
		||||
@@ -221,7 +229,7 @@ String AST::to_string()
 | 
			
		||||
				);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if ( Parent && Parent->Type != ECode::Typedef )
 | 
			
		||||
			if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
 | 
			
		||||
				result.append(";");
 | 
			
		||||
		}
 | 
			
		||||
		break;
 | 
			
		||||
@@ -238,7 +246,7 @@ String AST::to_string()
 | 
			
		||||
 | 
			
		||||
			result.append_fmt( "%s : %s", Name, UnderlyingType->to_string() );
 | 
			
		||||
 | 
			
		||||
			if ( Parent && Parent->Type != ECode::Typedef )
 | 
			
		||||
			if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
 | 
			
		||||
				result.append(";");
 | 
			
		||||
		}
 | 
			
		||||
		break;
 | 
			
		||||
@@ -282,7 +290,7 @@ String AST::to_string()
 | 
			
		||||
				result.append_fmt( "%s ", Attributes->to_string() );
 | 
			
		||||
 | 
			
		||||
			if ( Specs )
 | 
			
		||||
				result.append_fmt( "%s\n", Specs->to_string() );
 | 
			
		||||
				result.append_fmt( "%s", Specs->to_string() );
 | 
			
		||||
 | 
			
		||||
			if ( ReturnType )
 | 
			
		||||
				result.append_fmt( "%s %s(", ReturnType->to_string(), Name );
 | 
			
		||||
@@ -322,7 +330,7 @@ String AST::to_string()
 | 
			
		||||
				result.append_fmt( "%s ", Attributes->to_string() );
 | 
			
		||||
 | 
			
		||||
			if ( Specs )
 | 
			
		||||
				result.append_fmt( "%s\n", Specs->to_string() );
 | 
			
		||||
				result.append_fmt( "%s", Specs->to_string() );
 | 
			
		||||
 | 
			
		||||
			if ( ReturnType )
 | 
			
		||||
				result.append_fmt( "%s %s(", ReturnType->to_string(), Name );
 | 
			
		||||
@@ -514,7 +522,7 @@ String AST::to_string()
 | 
			
		||||
		break;
 | 
			
		||||
 | 
			
		||||
		case Preprocess_Define:
 | 
			
		||||
			result.append_fmt( "#define %s %s", Name, Content );
 | 
			
		||||
			result.append_fmt( "#define %s%s", Name, Content );
 | 
			
		||||
		break;
 | 
			
		||||
 | 
			
		||||
		case Preprocess_If:
 | 
			
		||||
@@ -542,7 +550,7 @@ String AST::to_string()
 | 
			
		||||
		break;
 | 
			
		||||
 | 
			
		||||
		case Preprocess_EndIf:
 | 
			
		||||
			result.append_fmt( "#endif" );
 | 
			
		||||
			result.append_fmt( "#endif\n" );
 | 
			
		||||
		break;
 | 
			
		||||
 | 
			
		||||
		case Preprocess_Pragma:
 | 
			
		||||
@@ -619,7 +627,7 @@ String AST::to_string()
 | 
			
		||||
				result.append_fmt( "struct %s\n{\n%s\n}", Name, Body->to_string() );
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if ( Parent && Parent->Type != ECode::Typedef )
 | 
			
		||||
			if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
 | 
			
		||||
				result.append(";");
 | 
			
		||||
		}
 | 
			
		||||
		break;
 | 
			
		||||
@@ -634,7 +642,7 @@ String AST::to_string()
 | 
			
		||||
 | 
			
		||||
			else result.append_fmt( "struct %s", Name );
 | 
			
		||||
 | 
			
		||||
			if ( Parent && Parent->Type != ECode::Typedef )
 | 
			
		||||
			if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
 | 
			
		||||
				result.append(";");
 | 
			
		||||
		}
 | 
			
		||||
		break;
 | 
			
		||||
@@ -659,11 +667,11 @@ String AST::to_string()
 | 
			
		||||
 | 
			
		||||
			if ( UnderlyingType->Type == Typename && UnderlyingType->ArrExpr )
 | 
			
		||||
			{
 | 
			
		||||
				result.append_fmt( "[%s];\n", UnderlyingType->ArrExpr->to_string() );
 | 
			
		||||
				result.append_fmt( "[%s];", UnderlyingType->ArrExpr->to_string() );
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
			{
 | 
			
		||||
				result.append( ";\n" );
 | 
			
		||||
				result.append( ";" );
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		break;
 | 
			
		||||
@@ -713,9 +721,7 @@ String AST::to_string()
 | 
			
		||||
				);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			bool add_semicolon = Parent && Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable;
 | 
			
		||||
 | 
			
		||||
			if ( add_semicolon )
 | 
			
		||||
			if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
 | 
			
		||||
				result.append(";");
 | 
			
		||||
		}
 | 
			
		||||
		break;
 | 
			
		||||
@@ -765,7 +771,7 @@ String AST::to_string()
 | 
			
		||||
					result.append_fmt( "[%s]", ValueType->ArrExpr->to_string() );
 | 
			
		||||
 | 
			
		||||
				if ( BitfieldSize )
 | 
			
		||||
					result.append_fmt( " : %lu", BitfieldSize );
 | 
			
		||||
					result.append_fmt( " : %s", BitfieldSize->to_string() );
 | 
			
		||||
 | 
			
		||||
				if ( Value )
 | 
			
		||||
					result.append_fmt( " = %s", Value->to_string() );
 | 
			
		||||
@@ -776,7 +782,7 @@ String AST::to_string()
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if ( BitfieldSize )
 | 
			
		||||
				result.append_fmt( "%s : %lu", ValueType->to_string(), BitfieldSize );
 | 
			
		||||
				result.append_fmt( "%s : %s", ValueType->to_string(), BitfieldSize->to_string() );
 | 
			
		||||
 | 
			
		||||
			else if ( UnderlyingType->ArrExpr )
 | 
			
		||||
				result.append_fmt( "%s %s[%s];", UnderlyingType->to_string(), Name, UnderlyingType->ArrExpr->to_string() );
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user