Browse Source

kommentare zu codeline hinzugefügt

Kolja Strohm 5 years ago
parent
commit
1bd1625c85

+ 4 - 0
src/codeline/AbstractForLoop.java

@@ -17,6 +17,10 @@ public abstract class AbstractForLoop<T> extends CodeLine {
 
     private String loopVar;
 
+    /**
+     * Erstellt eine Abstrakte Forschleife
+     * @param varName Der Name der Schleifenvariable
+     */
     public AbstractForLoop( String varName )
     {
         this.loopVar = varName;

+ 1 - 1
src/codeline/CodeLine.java

@@ -50,7 +50,7 @@ public abstract class CodeLine {
     public void runBackward( Memory m )
     {
     	if( actions.size() != 0 )
-    	    actions.pop().backward( m );
+    	    actions.pop().backward( m ); // Arbeite den Stack von Rückwärts Aktionen ab
     }
 
     /**

+ 2 - 2
src/codeline/DeclareVariable.java

@@ -43,8 +43,8 @@ public abstract class DeclareVariable <T> extends CodeLine {
 		
 		oldExists = m.isDefined( name, vis );
 		T oldVal = m.read( name, vis );
-		m.declare( name, value( m.createReadOnlyMemory() ), vis );
-		actions.push( (Memory mem) -> {
+		m.declare( name, value( m.createReadOnlyMemory() ), vis ); // deklariere die Variable je nach Sichtbarkeit im aktuellen Stack oder im Globalen Speicher
+		actions.push( (Memory mem) -> { // Rückwärts machen
 			mem.undeclare( name, vis );
             if( oldExists )
 				mem.write( name, oldVal, vis );

+ 6 - 2
src/codeline/ForEachLoop.java

@@ -19,6 +19,10 @@ public abstract class ForEachLoop <T> extends CodeLine {
 
     private String loopVar;
 	
+    /**
+     * Erstelle eine for-each Schleife
+     * @param varName Der Name der Schleifenvariable
+     */
 	public ForEachLoop( String varName )
 	{
 		this.loopVar = varName;
@@ -42,7 +46,7 @@ public abstract class ForEachLoop <T> extends CodeLine {
 			m.addFrame( new StackFrame( FrameType.LOOP ) );
             m.declare( loopVar, list( m.createReadOnlyMemory() ).get( m.read( "line_" + lineId + "_index", Visibility.LOCAL ) ), Visibility.LOCAL ); // set loop variable
 			actions.push( (Memory mem) -> {
-				mem.removeFrame();
+				mem.removeFrame(); // remove Loop Stack Frame
 				mem.undeclare( "line_" + lineId + "_index", Visibility.LOCAL );
 			} );
 		}
@@ -64,7 +68,7 @@ public abstract class ForEachLoop <T> extends CodeLine {
 			m.declare( loopVar, list( m.createReadOnlyMemory() ).get( m.read( "line_" + lineId + "_index", Visibility.LOCAL ) ), Visibility.LOCAL ); // update loop variable
 			actions.push( (Memory mem) -> {
 				mem.removeFrame();
-				mem.addFrame( old );
+				mem.addFrame( old ); // restore last loop stack
 				mem.write( "line_" + lineId + "_index", oldIndex, Visibility.LOCAL );
 			});
 		}

+ 2 - 2
src/codeline/ForLoop.java

@@ -39,7 +39,7 @@ public abstract class ForLoop extends CodeLine {
 			m.addFrame( new StackFrame( FrameType.LOOP ) );
             m.declare( loopVar, minimum( m.createReadOnlyMemory() ), Visibility.LOCAL ); // set loop variable
 			actions.push( (Memory mem) -> {
-				mem.removeFrame();
+				mem.removeFrame(); // remove loop stack
 				mem.undeclare( "line_" + lineId + "_index", Visibility.LOCAL );
 			} );
 		}
@@ -62,7 +62,7 @@ public abstract class ForLoop extends CodeLine {
 			m.declare( loopVar, (int)m.read( "line_" + lineId + "_index", Visibility.LOCAL ), Visibility.LOCAL ); // update loop variable
 			actions.push( (Memory mem) -> {
 				mem.removeFrame();
-				mem.addFrame( old );
+				mem.addFrame( old ); // restore last loop stack
 				mem.write( "line_" + lineId + "_index", oldIndex, Visibility.LOCAL );
 			});
 		}

+ 8 - 3
src/codeline/FunctionCall.java

@@ -14,6 +14,11 @@ public class FunctionCall extends CodeLine {
 	private PseudoCodeNode target;
 	private String[] params;
 	
+	/**
+	 * Erstellt einen neuen Funktionsaufruf
+	 * @param function der PseudoCode Knoten der Funktion (sollte eine FunctionDefinition CodeLine beinhalten aber das ist nicht Pflicht)
+	 * @param params Liste mit namen von Lokalen variablen, welche als Parameter übergeben werden sollen
+	 */
 	public FunctionCall( PseudoCodeNode function, String[] params )
 	{
 		this.target = function;
@@ -24,11 +29,11 @@ public class FunctionCall extends CodeLine {
 	public ControlFlow runForward(Memory m) {
 		int index = 1;
 		for( String p : params )
-		{
+		{ // Schreibe die Parameter der Funktion in die dafür vorgesehenen Globalen Register
 			m.declare( "param" + index, m.read( p, Visibility.LOCAL ), Visibility.GLOBAL );
 			index++;
 		}
-		actions.push( (Memory mem) -> {
+		actions.push( (Memory mem) -> { // Rückwärtsaktion merken
 			int ind = 1;
 			for( @SuppressWarnings("unused") String p : params )
 			{
@@ -36,7 +41,7 @@ public class FunctionCall extends CodeLine {
 				ind++;
 			}
 		} );
-		return new ControlFlow( target );
+		return new ControlFlow( target ); // Gibt ein ControlFlow Object zurück, welches dem Prozessor die Anweisung gibt zu einem Bestimmten Knoten zu springen
 	}
 
 }

+ 11 - 7
src/codeline/FunctionDefinition.java

@@ -14,6 +14,10 @@ public class FunctionDefinition extends CodeLine {
 
 	private String[] params;
 	
+	/**
+	 * Erstellt eine neue Funktion
+	 * @param params Eine Liste mit Namen von Argumenten die automatisch beim Aufruf aus den Globalen Registern in das neue Stackframe geladen werden sollen
+	 */
 	public FunctionDefinition( String[] params )
 	{
 		this.params = params;
@@ -22,19 +26,19 @@ public class FunctionDefinition extends CodeLine {
 	@Override
 	public ControlFlow runForward(Memory m) {
 		if( !m.isDefined( "line_" + lineId + "_inside", Visibility.LOCAL ) )
-		{
-			m.addFrame( new StackFrame( FrameType.FUNCTION ) );
+		{ // Funktion wurde noch nicht aufgerufen
+			m.addFrame( new StackFrame( FrameType.FUNCTION ) ); // Füge neues Stackframe hinzu
 			m.declare( "line_" + lineId + "_inside", true, Visibility.LOCAL );
 			int index = 1;
 			Object[] olds = new Object[ params.length ];
 			for( String p : params )
-			{
+			{ // Lade alle Parameter aus den Globalen Registern
 				olds[ index - 1 ] = m.read( "param" + index, Visibility.GLOBAL );
-				m.declare( p, olds[ index - 1 ], Visibility.LOCAL );
+				m.declare( p, olds[ index - 1 ], Visibility.LOCAL ); // Speichere sie im Stack
 				m.undeclare( "param" + index, Visibility.GLOBAL );
 				index++;
 			}
-			actions.push( (Memory mem) -> {
+			actions.push( (Memory mem) -> { // merkt sich die Rückwärtsaktion
 				mem.removeFrame();
 				int i = 1;
 				for( @SuppressWarnings("unused") String p : params )
@@ -43,10 +47,10 @@ public class FunctionDefinition extends CodeLine {
 					i++;
 				}
 			} );
-			return new ControlFlow( ControlFlow.STEP_INTO );
+			return new ControlFlow( ControlFlow.STEP_INTO ); // springe in die Funktion
 		}
 		else
-		{
+		{ // Funktion ist bereits follständig ausgeführt worden
 			StackFrame frame = m.removeFrame();
 			actions.push( (Memory mem) -> {
 				mem.addFrame( frame );

+ 7 - 6
src/codeline/IfLoop.java

@@ -16,26 +16,27 @@ public abstract class IfLoop extends CodeLine {
 
 	@Override
 	public ControlFlow runForward(Memory m) {
+		// Prüfe ob die Kindknoten bereits ausgeführt wurden
 		if( m.isDefined( "line_" + lineId + "_inside", Visibility.LOCAL ) )
-		{
+		{ // Wurde bereits ausgeführt
 			StackFrame old = m.removeFrame();
 			actions.push( (Memory mem) -> {
 				mem.addFrame( old );
 			} );
-            return new ControlFlow( ControlFlow.STEP_OVER );
+            return new ControlFlow( ControlFlow.STEP_OVER ); // Springe zum nachfolgenden Knoten
 		}
 		else
-		{
-            if( condition( m.createReadOnlyMemory() ) ) {
+		{ // Wurde noch nicht ausgeführt
+            if( condition( m.createReadOnlyMemory() ) ) { // Prüfe ob die Bedingung erfüllt ist
             	m.addFrame( new StackFrame( FrameType.LOOP ) );
             	m.declare( "line_" + lineId + "_inside", true, Visibility.LOCAL );
             	actions.push( (Memory mem) -> {
             		mem.removeFrame();
             	} );
-            	return new ControlFlow( ControlFlow.STEP_INTO );
+            	return new ControlFlow( ControlFlow.STEP_INTO ); // Springe in das If rein
             } else {
             	actions.push( (Memory mem) -> {} );
-                return new ControlFlow( ControlFlow.STEP_OVER );
+                return new ControlFlow( ControlFlow.STEP_OVER ); // Springe zum nachfolgenden Knoten
             }
 		}
 	}

+ 6 - 2
src/codeline/SetVariable.java

@@ -16,6 +16,10 @@ public abstract class SetVariable <T> extends CodeLine {
 
     private String name;
     
+    /**
+     * 
+     * @param name Der Name der Variable, welche verändert werden soll
+     */
     public SetVariable( String name )
     {
         this.name = name;
@@ -25,9 +29,9 @@ public abstract class SetVariable <T> extends CodeLine {
     public ControlFlow runForward(Memory m) {
         
         T oldVal = m.read( name, Visibility.LOCAL );
-        m.write( name, value( m.createReadOnlyMemory() ), Visibility.LOCAL );
+        m.write( name, value( m.createReadOnlyMemory() ), Visibility.LOCAL ); // Schreibe in die VAriable
         actions.push( (Memory mem) -> {
-            mem.write( name, oldVal, Visibility.LOCAL );
+            mem.write( name, oldVal, Visibility.LOCAL ); // Rückwärts
         });
         return new ControlFlow( ControlFlow.STEP_OVER );
     }