Skip to content

Commit cf3d409

Browse files
committed
修复了list,优化了代码
1 parent 7f371a6 commit cf3d409

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+520
-784
lines changed

src/main/java/top/mcfpp/mni/NBTListData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static void addAll(@NotNull NBTList list, NBTList caller){
114114
Function.Companion.addCommand(command);
115115
}
116116

117-
@MNIFunction(normalParams = {"int index, E e"}, caller = "list", genericType = "E")
117+
@MNIFunction(normalParams = {"int index", "E e"}, caller = "list", genericType = "E")
118118
public static void insert(MCInt index, Var<?> e, NBTList caller){
119119
if(e instanceof MCFPPValue<?> && (MCInt)index instanceof MCIntConcrete indexC){
120120
//都是确定的
@@ -257,7 +257,7 @@ public static void indexOf(@NotNull Var<?> e, NBTList caller, ValueWrapper<MCInt
257257
returnVar.setValue(index);
258258
}
259259

260-
@MNIFunction(normalParams = {"E e"}, caller = "list<E>", returnType = "int")
260+
@MNIFunction(normalParams = {"E e"}, caller = "list<E>", genericType = "E", returnType = "int")
261261
public static void lastIndexOf(Var<?> e, NBTList caller, ValueWrapper<MCInt> returnVar){
262262
var n = e.toNBTVar();
263263
element.assignedBy(n);

src/main/java/top/mcfpp/mni/minecraft/PlayerEntityConcreteData.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class PlayerEntityConcreteData {
1919

2020
public static void grant(Advancement advancement, PlayerVar.PlayerEntityVarConcrete caller, ValueWrapper<CommandReturn> returnValue) {
2121
Command[] command;
22-
String playerName = caller.value.getValue();
22+
String playerName = caller.getValue().getValue();
2323
if(advancement instanceof AdvancementConcrete){
2424
command = new Command[] {new Command("advancement grant " + playerName + " only " + ((AdvancementConcrete) advancement).getValue())};
2525
}else {
@@ -30,16 +30,16 @@ public static void grant(Advancement advancement, PlayerVar.PlayerEntityVarConcr
3030
}
3131

3232
public static void grantAll(PlayerVar.PlayerEntityVarConcrete caller, ValueWrapper<CommandReturn> returnValue) {
33-
String playerName = caller.value.getValue();
33+
String playerName = caller.getValue().getValue();
3434
var command = new Command("advancement grant " + playerName + " everything");
3535
returnValue.setValue(new CommandReturn(command, "return"));
3636
Function.Companion.addCommand(command);
3737
}
3838

3939
@MNIFunction(normalParams = {"Advancement advancement"}, caller = "Player", returnType = "CommandReturn")
40-
public static void grantFrom(Advancement advancement, PlayerVar.PlayerEntityVar caller, ValueWrapper<CommandReturn> returnValue) {
40+
public static void grantFrom(Advancement advancement, PlayerVar.PlayerEntityVarConcrete caller, ValueWrapper<CommandReturn> returnValue) {
4141
Command[] commands;
42-
String playerName = caller.getEntity().getName();
42+
String playerName = caller.getValue().getValue();
4343
if(advancement instanceof AdvancementConcrete){
4444
commands = new Command[]{new Command("advancement grant " + playerName + " from " + ((AdvancementConcrete) advancement).getValue())};
4545
}else {
@@ -50,9 +50,9 @@ public static void grantFrom(Advancement advancement, PlayerVar.PlayerEntityVar
5050
}
5151

5252
@MNIFunction(normalParams = {"Advancement advancement"}, caller = "Player", returnType = "CommandReturn")
53-
public static void grantThrough(Advancement advancement, PlayerVar.PlayerEntityVar caller, ValueWrapper<CommandReturn> returnValue) {
53+
public static void grantThrough(Advancement advancement, PlayerVar.PlayerEntityVarConcrete caller, ValueWrapper<CommandReturn> returnValue) {
5454
Command[] commands;
55-
String playerName = caller.getEntity().getName();
55+
String playerName = caller.getValue().getValue();
5656
if(advancement instanceof AdvancementConcrete){
5757
commands = new Command[]{new Command("advancement grant " + playerName + " through " + ((AdvancementConcrete) advancement).getValue())};
5858
}else {
@@ -63,9 +63,9 @@ public static void grantThrough(Advancement advancement, PlayerVar.PlayerEntityV
6363
}
6464

6565
@MNIFunction(normalParams = {"Advancement advancement"}, caller = "Player", returnType = "CommandReturn")
66-
public static void grantUntil(Advancement advancement, PlayerVar.PlayerEntityVar caller, ValueWrapper<CommandReturn> returnValue) {
66+
public static void grantUntil(Advancement advancement, PlayerVar.PlayerEntityVarConcrete caller, ValueWrapper<CommandReturn> returnValue) {
6767
Command[] commands;
68-
String playerName = caller.getEntity().getName();
68+
String playerName = caller.getValue().getValue();
6969
if(advancement instanceof AdvancementConcrete){
7070
commands = new Command[]{new Command("advancement grant " + playerName + " until " + ((AdvancementConcrete) advancement).getValue())};
7171
}else {
@@ -78,7 +78,7 @@ public static void grantUntil(Advancement advancement, PlayerVar.PlayerEntityVar
7878
@MNIFunction(normalParams = {"Advancement advancement"}, caller = "Player", returnType = "CommandReturn")
7979
public static void revoke(Advancement advancement, PlayerVar.PlayerEntityVarConcrete caller, ValueWrapper<CommandReturn> returnValue) {
8080
Command[] command;
81-
String playerName = caller.value.getValue();
81+
String playerName = caller.getValue().getValue();
8282
if(advancement instanceof AdvancementConcrete){
8383
command = new Command[] {new Command("advancement revoke " + playerName + " only " + ((AdvancementConcrete) advancement).getValue())};
8484
}else {
@@ -90,7 +90,7 @@ public static void revoke(Advancement advancement, PlayerVar.PlayerEntityVarConc
9090

9191
@MNIFunction(caller = "Player", returnType = "CommandReturn")
9292
public static void revokeAll(PlayerVar.PlayerEntityVarConcrete caller, ValueWrapper<CommandReturn> returnValue) {
93-
String playerName = caller.value.getValue();
93+
String playerName = caller.getValue().getValue();
9494
var command = new Command("advancement revoke " + playerName + " everything");
9595
returnValue.setValue(new CommandReturn(command, "return"));
9696
Function.Companion.addCommand(command);
@@ -99,7 +99,7 @@ public static void revokeAll(PlayerVar.PlayerEntityVarConcrete caller, ValueWrap
9999
@MNIFunction(normalParams = {"Advancement advancement"}, caller = "Player", returnType = "CommandReturn")
100100
public static void revokeFrom(Advancement advancement, PlayerVar.PlayerEntityVarConcrete caller, ValueWrapper<CommandReturn> returnValue) {
101101
Command[] command;
102-
String playerName = caller.value.getValue();
102+
String playerName = caller.getValue().getValue();
103103
if(advancement instanceof AdvancementConcrete){
104104
command = new Command[] {new Command("advancement revoke " + playerName + " from " + ((AdvancementConcrete) advancement).getValue())};
105105
}else {
@@ -112,7 +112,7 @@ public static void revokeFrom(Advancement advancement, PlayerVar.PlayerEntityVar
112112
@MNIFunction(normalParams = {"Advancement advancement"}, caller = "Player", returnType = "CommandReturn")
113113
public static void revokeThrough(Advancement advancement, PlayerVar.PlayerEntityVarConcrete caller, ValueWrapper<CommandReturn> returnValue) {
114114
Command[] command;
115-
String playerName = caller.value.getValue();
115+
String playerName = caller.getValue().getValue();
116116
if(advancement instanceof AdvancementConcrete){
117117
command = new Command[] {new Command("advancement revoke " + playerName + " through " + ((AdvancementConcrete) advancement).getValue())};
118118
}else {
@@ -125,7 +125,7 @@ public static void revokeThrough(Advancement advancement, PlayerVar.PlayerEntity
125125
@MNIFunction(normalParams = {"Advancement advancement"}, caller = "Player", returnType = "CommandReturn")
126126
public static void revokeUntil(Advancement advancement, PlayerVar.PlayerEntityVarConcrete caller, ValueWrapper<CommandReturn> returnValue) {
127127
Command[] command;
128-
String playerName = caller.value.getValue();
128+
String playerName = caller.getValue().getValue();
129129
if(advancement instanceof AdvancementConcrete){
130130
command = new Command[] {new Command("advancement revoke " + playerName + " until " + ((AdvancementConcrete) advancement).getValue())};
131131
}else {
@@ -139,7 +139,7 @@ public static void revokeUntil(Advancement advancement, PlayerVar.PlayerEntityVa
139139
public static void getAttribute(MCString id, MCFloat scale, PlayerVar.PlayerEntityVarConcrete caller, ValueWrapper<CommandReturn> returnValue){
140140
Command[] commands;
141141
Command command;
142-
String playerName = caller.value.getValue();
142+
String playerName = caller.getValue().getValue();
143143
if(id instanceof MCStringConcrete idC){
144144
command = new Command("attribute " + playerName + " " + idC.getValue().getValue() + " get");
145145
}else {

src/main/kotlin/top/mcfpp/Project.kt

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
package top.mcfpp
22

3-
import com.alibaba.fastjson2.*
3+
import com.alibaba.fastjson2.JSONArray
4+
import com.alibaba.fastjson2.JSONObject
45
import com.ibm.icu.impl.data.ResourceReader
56
import org.antlr.v4.runtime.ParserRuleContext
67
import org.antlr.v4.runtime.tree.ParseTree
7-
import org.apache.logging.log4j.*
8+
import org.apache.logging.log4j.LogManager
9+
import org.apache.logging.log4j.Logger
810
import top.mcfpp.annotations.InsertCommand
9-
import top.mcfpp.io.LibReader
10-
import top.mcfpp.io.LibWriter
11-
import top.mcfpp.io.MCFPPFile
1211
import top.mcfpp.core.lang.MCFloat
1312
import top.mcfpp.core.lang.UnresolvedVar
1413
import top.mcfpp.core.lang.Var
15-
import top.mcfpp.model.*
14+
import top.mcfpp.io.LibReader
15+
import top.mcfpp.io.LibWriter
16+
import top.mcfpp.io.MCFPPFile
17+
import top.mcfpp.model.Native
18+
import top.mcfpp.model.ObjectClass
1619
import top.mcfpp.model.field.GlobalField
1720
import top.mcfpp.model.function.Function
1821
import top.mcfpp.util.LogProcessor
1922
import top.mcfpp.util.Utils
20-
import java.io.*
23+
import java.io.File
24+
import java.io.FileReader
25+
import java.io.IOException
2126
import java.net.URLClassLoader
2227
import java.nio.charset.StandardCharsets
2328
import java.nio.file.Path
2429
import java.nio.file.Paths
25-
import java.util.*
2630
import java.util.jar.JarFile
27-
import kotlin.collections.ArrayList
2831
import kotlin.io.path.*
2932

3033

@@ -261,8 +264,10 @@ object Project {
261264
//函数参数解析
262265
GlobalField.importedLibNamespaces.clear()
263266
//读取所有文件
264-
MCFPPFile.findFiles(config.sourcePath!!.absolutePathString()).forEach {
265-
files.add(MCFPPFile(it.toFile()))
267+
if (config.sourcePath != null) {
268+
MCFPPFile.findFiles(config.sourcePath!!.absolutePathString()).forEach {
269+
files.add(MCFPPFile(it.toFile()))
270+
}
266271
}
267272
stageProcessor[compileStage].forEach { it() }
268273
}

src/main/kotlin/top/mcfpp/antlr/MCFPPExprVisitor.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package top.mcfpp.antlr
22

33
import net.querz.nbt.io.SNBTUtil
4-
import net.querz.nbt.tag.*
4+
import net.querz.nbt.tag.DoubleTag
5+
import net.querz.nbt.tag.LongTag
6+
import net.querz.nbt.tag.StringTag
57
import top.mcfpp.Project
68
import top.mcfpp.annotations.InsertCommand
79
import top.mcfpp.core.lang.*
8-
import top.mcfpp.type.MCFPPEnumType
9-
import top.mcfpp.type.MCFPPGenericClassType
10-
import top.mcfpp.type.MCFPPType
11-
import top.mcfpp.core.lang.MCFPPValue
1210
import top.mcfpp.core.lang.nbt.*
1311
import top.mcfpp.lib.NBTPath
1412
import top.mcfpp.model.Class
@@ -22,6 +20,9 @@ import top.mcfpp.model.function.UnknownFunction
2220
import top.mcfpp.model.generic.Generic
2321
import top.mcfpp.model.generic.GenericClass
2422
import top.mcfpp.type.MCFPPBaseType
23+
import top.mcfpp.type.MCFPPEnumType
24+
import top.mcfpp.type.MCFPPGenericClassType
25+
import top.mcfpp.type.MCFPPType
2526
import top.mcfpp.util.BoolTag
2627
import top.mcfpp.util.LogProcessor
2728
import top.mcfpp.util.NBTUtil.toNBTByte
@@ -33,7 +34,6 @@ import top.mcfpp.util.StringHelper
3334
import top.mcfpp.util.TextTranslator
3435
import top.mcfpp.util.TextTranslator.translate
3536
import java.util.*
36-
import kotlin.collections.HashMap
3737

3838
/**
3939
* 获取表达式结果用的visitor。解析并计算一个形如a+b*c的表达式。
@@ -674,7 +674,11 @@ class MCFPPExprVisitor(private var defaultGenericClassType : MCFPPGenericClassTy
674674
for (expr in ctx.nbtList().expression()){
675675
valueList.add(visit(expr))
676676
}
677-
val re = NBTListConcrete(valueList, "", valueList.first().type)
677+
val re = if(valueList.isEmpty()){
678+
NBTListConcrete.getEmpty()
679+
}else{
680+
NBTListConcrete(valueList, "", valueList.first().type)
681+
}
678682
return if(re.value.all { it is MCFPPValue<*> }){
679683
re
680684
}else{

src/main/kotlin/top/mcfpp/antlr/MCFPPFieldVisitor.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ package top.mcfpp.antlr
22

33
import top.mcfpp.Project
44
import top.mcfpp.annotations.InsertCommand
5+
import top.mcfpp.annotations.MNIFunction
56
import top.mcfpp.antlr.mcfppParser.TemplateDeclarationContext
67
import top.mcfpp.compiletime.CompileTimeFunction
7-
import top.mcfpp.exception.*
8-
import top.mcfpp.io.MCFPPFile
98
import top.mcfpp.core.lang.*
10-
import top.mcfpp.type.MCFPPType
11-
import top.mcfpp.annotations.MNIFunction
12-
import top.mcfpp.type.MCFPPBaseType
9+
import top.mcfpp.exception.UndefinedException
10+
import top.mcfpp.exception.VariableConverseException
11+
import top.mcfpp.io.MCFPPFile
1312
import top.mcfpp.model.*
14-
import top.mcfpp.model.Class
1513
import top.mcfpp.model.Member.AccessModifier
1614
import top.mcfpp.model.accessor.*
1715
import top.mcfpp.model.field.GlobalField
@@ -20,12 +18,13 @@ import top.mcfpp.model.function.*
2018
import top.mcfpp.model.function.Function
2119
import top.mcfpp.model.generic.GenericExtensionFunction
2220
import top.mcfpp.model.generic.GenericFunction
21+
import top.mcfpp.type.MCFPPBaseType
22+
import top.mcfpp.type.MCFPPType
2323
import top.mcfpp.util.LogProcessor
2424
import top.mcfpp.util.StringHelper
2525
import top.mcfpp.util.TextTranslator
2626
import top.mcfpp.util.TextTranslator.translate
2727
import java.util.*
28-
import kotlin.collections.ArrayList
2928

3029
/**
3130
* 在编译工程之前,应当首先将所有文件中的资源全部遍历一次并写入缓存。
@@ -476,9 +475,9 @@ open class MCFPPFieldVisitor : mcfppParserBaseVisitor<Any?>() {
476475
MCFPPBaseType.Any
477476
}
478477
val `var` = type.buildUnConcrete(c.Identifier().text, Class.currClass!!)
479-
if(Class.currClass is ObjectClass){
478+
if(Class.currClass is ObjectClass && `var` is OnScoreboard){
480479
`var`.name = (Class.currClass as ObjectClass).uuid.toString()
481-
}else{
480+
}else if(`var` is OnScoreboard){
482481
`var`.name = "@s"
483482
}
484483
`var`.isDynamic = true

src/main/kotlin/top/mcfpp/core/lang/ClassPointer.kt

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ import java.util.*
2424
* 一个类的指针。类的地址储存在storage的uuid中中,因此一个类的指针实际上包含了两个信息,一个是指针代表的是[哪一个类][clazz],一个是指针指向的这个类的对象
2525
*在堆中的地址,即nbt uuid的值是多少。
2626
*
27-
* 指针继承于类[Var],然而它的[name]并没有额外的用处,因为我们并不需要关注这个指针处于哪一个类或者哪一个函数中。起到标识符作用的更多是[identifier]。
28-
* 事实上,指针的[name]和[identifier]拥有相同的值。
29-
*
3027
* 创建一个类的对象的时候,在分配完毕类的地址之后,将会立刻创建一个初始指针,这个指针指向了刚刚创建的对象的地址。
3128
* 而后进行的引用操作无非是把这个初始指针的记分板值赋给其他的指针。
3229
*
@@ -44,7 +41,7 @@ open class ClassPointer : Var<ClassPointer>{
4441
/**
4542
* 指针对应的类的标识符
4643
*/
47-
override var type: MCFPPType
44+
override lateinit var type: MCFPPType
4845

4946
val tag: String
5047
/**
@@ -62,18 +59,7 @@ open class ClassPointer : Var<ClassPointer>{
6259
* @param clazz 指针的类型
6360
* @param identifier 标识符
6461
*/
65-
constructor(clazz: Class, container: FieldContainer, identifier: String) {
66-
this.type = clazz.getType()
67-
this.identifier = identifier
68-
this.name = container.prefix + identifier
69-
instanceField = CompoundDataField(clazz.field)
70-
}
71-
72-
/**
73-
* 创建一个指针
74-
* @param clazz 指针的类型
75-
* @param identifier 标识符
76-
*/
62+
@Suppress("LeakingThis")
7763
constructor(clazz: Class, identifier: String) {
7864
this.type = clazz.getType()
7965
this.identifier = identifier
@@ -84,6 +70,7 @@ open class ClassPointer : Var<ClassPointer>{
8470
* 复制一个指针
8571
* @param classPointer 被复制的指针
8672
*/
73+
@Suppress("LeakingThis")
8774
constructor(classPointer: ClassPointer) : super(classPointer) {
8875
type = classPointer.type
8976
instanceField = classPointer.instanceField
@@ -261,8 +248,6 @@ class ClassPointerConcrete: ClassPointer, MCFPPValue<Class>{
261248

262249
override lateinit var value: Class
263250

264-
constructor(clazz: Class, container: FieldContainer, identifier: String): super(clazz, container, identifier)
265-
266251
constructor(clazz: Class, identifier: String): super(clazz, identifier)
267252

268253
constructor(value: Class , classPointer: ClassPointer) : super(classPointer) {

src/main/kotlin/top/mcfpp/core/lang/CommandReturn.kt

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package top.mcfpp.core.lang
22

33
import top.mcfpp.command.Command
4-
import top.mcfpp.type.MCFPPType
54
import top.mcfpp.lib.NBTPath
65
import top.mcfpp.model.CompoundData
7-
import top.mcfpp.model.FieldContainer
86
import top.mcfpp.model.Member
97
import top.mcfpp.model.function.Function
108
import top.mcfpp.model.function.UnknownFunction
119
import top.mcfpp.type.MCFPPPrivateType
10+
import top.mcfpp.type.MCFPPType
1211
import java.util.*
1312

1413
class CommandReturn : Var<CommandReturn> {
@@ -21,19 +20,6 @@ class CommandReturn : Var<CommandReturn> {
2120

2221
override var type: MCFPPType = MCFPPPrivateType.CommandReturn
2322

24-
/**
25-
* 创建一个string类型的变量。它的mc名和变量所在的域容器有关。
26-
*
27-
* @param identifier 标识符。默认为
28-
*/
29-
constructor(
30-
command: Command,
31-
curr: FieldContainer,
32-
identifier: String = UUID.randomUUID().toString()
33-
) : this(command, curr.prefix + identifier) {
34-
this.identifier = identifier
35-
}
36-
3723
/**
3824
* 创建一个string值。它的标识符和mc名相同。
3925
* @param identifier identifier
@@ -105,7 +91,7 @@ class CommandSuccess(val re: CommandReturn) : Var<CommandSuccess>("success") {
10591
get() {
10692
return re.nbtPath.memberIndex("success")
10793
}
108-
set(value) {}
94+
set(_) {}
10995

11096
override fun doAssignedBy(b: Var<*>): CommandSuccess = this
11197

@@ -138,7 +124,7 @@ class CommandResult(val re: CommandReturn): Var<CommandResult>("result"){
138124
get() {
139125
return re.nbtPath.memberIndex("result")
140126
}
141-
set(value) {}
127+
set(_) {}
142128

143129
override fun doAssignedBy(b: Var<*>): CommandResult = this
144130

src/main/kotlin/top/mcfpp/core/lang/ConcreteVar.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package top.mcfpp.core.lang
22

3-
import com.github.javaparser.utils.Log
4-
import top.mcfpp.model.Member
5-
import top.mcfpp.model.function.Function
6-
import top.mcfpp.type.MCFPPType
73
import top.mcfpp.util.LogProcessor
84

95
@Suppress("UNCHECKED_CAST")

0 commit comments

Comments
 (0)