Skip to content
Snippets Groups Projects
Commit fd7a059b authored by Anian Bühler's avatar Anian Bühler
Browse files

added memsetBlock, memcpyBlock & strcpyBlock

parent d2dc9821
No related branches found
No related tags found
1 merge request!1dev_prefereences to master
package com.ardublock.translator.block.arrays;
import java.util.ResourceBundle;
import com.ardublock.translator.Translator;
import com.ardublock.translator.block.TranslatorBlock;
import com.ardublock.translator.block.exception.BlockException;
import com.ardublock.translator.block.exception.SocketNullException;
import com.ardublock.translator.block.exception.SubroutineNotDeclaredException;
import com.ardublock.translator.block.numbers.ConstantStringBlock;
import com.ardublock.translator.block.numbers.LocalVariableStringBlock;
import com.ardublock.translator.block.numbers.VariableStringBlock;
public class MemcpyBlock extends TranslatorBlock
{
private static ResourceBundle uiMessageBundle = ResourceBundle.getBundle("com/ardublock/block/ardublock");
public MemcpyBlock(Long blockId, Translator translator, String codePrefix, String codeSuffix, String label)
{
super(blockId, translator, codePrefix, codeSuffix, label);
}
@Override
public String toCode() throws SocketNullException, SubroutineNotDeclaredException
{
TranslatorBlock tb_destination = this.getRequiredTranslatorBlockAtSocket(0);
TranslatorBlock tb_source = this.getRequiredTranslatorBlockAtSocket(1);
TranslatorBlock tb_length = this.getRequiredTranslatorBlockAtSocket(2);
String destinationArray = tb_destination.toCode();
String sourceArray = tb_source.toCode();
String lengthOfData = tb_length.toCode();
if (!(tb_destination instanceof VariableStringBlock) && !(tb_destination instanceof LocalVariableStringBlock) && !(tb_destination instanceof ConstantStringBlock)
&& !(tb_source instanceof VariableStringBlock) && !(tb_source instanceof LocalVariableStringBlock) && !(tb_source instanceof ConstantStringBlock)) {
throw new BlockException(blockId, uiMessageBundle.getString("ardublock.error_msg.string_var_slot"));
}
String ret = "memcpy("+destinationArray+", " + sourceArray + ", "+lengthOfData+")";
return ret;
}
}
package com.ardublock.translator.block.arrays;
import java.util.ResourceBundle;
import com.ardublock.translator.Translator;
import com.ardublock.translator.block.TranslatorBlock;
import com.ardublock.translator.block.exception.BlockException;
import com.ardublock.translator.block.exception.SocketNullException;
import com.ardublock.translator.block.exception.SubroutineNotDeclaredException;
import com.ardublock.translator.block.numbers.ConstantStringBlock;
import com.ardublock.translator.block.numbers.LocalVariableStringBlock;
import com.ardublock.translator.block.numbers.VariableStringBlock;
public class MemsetBlock extends TranslatorBlock
{
private static ResourceBundle uiMessageBundle = ResourceBundle.getBundle("com/ardublock/block/ardublock");
public MemsetBlock(Long blockId, Translator translator, String codePrefix, String codeSuffix, String label)
{
super(blockId, translator, codePrefix, codeSuffix, label);
}
@Override
public String toCode() throws SocketNullException, SubroutineNotDeclaredException
{
TranslatorBlock tb_destination = this.getRequiredTranslatorBlockAtSocket(0);
TranslatorBlock tb_insert = this.getRequiredTranslatorBlockAtSocket(1);
TranslatorBlock tb_length = this.getRequiredTranslatorBlockAtSocket(2);
String destinationArray = tb_destination.toCode();
String insertChar = tb_insert.toCode();
String numOfReplacedChars = tb_length.toCode();
if (!(tb_destination instanceof VariableStringBlock) && !(tb_destination instanceof LocalVariableStringBlock) && !(tb_destination instanceof ConstantStringBlock)) {
throw new BlockException(blockId, uiMessageBundle.getString("ardublock.error_msg.string_var_slot"));
}
String ret = "memset("+destinationArray+", " + insertChar + ", "+numOfReplacedChars+")";
return ret;
}
}
...@@ -33,7 +33,7 @@ public class SetterCharArrayBlock extends TranslatorBlock ...@@ -33,7 +33,7 @@ public class SetterCharArrayBlock extends TranslatorBlock
String value = tb_Value.toCode(); String value = tb_Value.toCode();
if (!(tb_Name instanceof VariableStringBlock) && !(tb_Name instanceof LocalVariableStringBlock) && !(tb_Name instanceof ConstantStringBlock)) { if (!(tb_Name instanceof VariableStringBlock) && !(tb_Name instanceof LocalVariableStringBlock) && !(tb_Name instanceof ConstantStringBlock)) {
throw new BlockException(blockId, uiMessageBundle.getString("ardublock.error_msg.number_var_slot")); throw new BlockException(blockId, uiMessageBundle.getString("ardublock.error_msg.string_var_slot"));
} }
/* if (!(tb_Pos instanceof VariableNumberBlock) && !(tb_Pos instanceof LocalVariableNumberBlock) && !(tb_Pos instanceof NumberBlock)) { /* if (!(tb_Pos instanceof VariableNumberBlock) && !(tb_Pos instanceof LocalVariableNumberBlock) && !(tb_Pos instanceof NumberBlock)) {
throw new BlockException(blockId, uiMessageBundle.getString("ardublock.error_msg.number_var_slot")); throw new BlockException(blockId, uiMessageBundle.getString("ardublock.error_msg.number_var_slot"));
......
package com.ardublock.translator.block.arrays;
import java.util.ResourceBundle;
import com.ardublock.translator.Translator;
import com.ardublock.translator.block.TranslatorBlock;
import com.ardublock.translator.block.exception.BlockException;
import com.ardublock.translator.block.exception.SocketNullException;
import com.ardublock.translator.block.exception.SubroutineNotDeclaredException;
import com.ardublock.translator.block.numbers.ConstantStringBlock;
import com.ardublock.translator.block.numbers.LocalVariableStringBlock;
import com.ardublock.translator.block.numbers.VariableStringBlock;
public class StrcpyBlock extends TranslatorBlock
{
private static ResourceBundle uiMessageBundle = ResourceBundle.getBundle("com/ardublock/block/ardublock");
public StrcpyBlock(Long blockId, Translator translator, String codePrefix, String codeSuffix, String label)
{
super(blockId, translator, codePrefix, codeSuffix, label);
}
@Override
public String toCode() throws SocketNullException, SubroutineNotDeclaredException
{
TranslatorBlock tb_destination = this.getRequiredTranslatorBlockAtSocket(0);
TranslatorBlock tb_source = this.getRequiredTranslatorBlockAtSocket(1);
String destinationArray = tb_destination.toCode();
String sourceArray = tb_source.toCode();
if (!(tb_destination instanceof VariableStringBlock) && !(tb_destination instanceof LocalVariableStringBlock) && !(tb_destination instanceof ConstantStringBlock)
&& !(tb_source instanceof VariableStringBlock) && !(tb_source instanceof LocalVariableStringBlock) && !(tb_source instanceof ConstantStringBlock)) {
throw new BlockException(blockId, uiMessageBundle.getString("ardublock.error_msg.string_var_slot"));
}
String ret = "strcpy("+destinationArray+", " + sourceArray + ")";
return ret;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment