Skip to content

Commit

Permalink
Merge c166ca5 into cd9fb4a
Browse files Browse the repository at this point in the history
  • Loading branch information
deavmi committed May 11, 2024
2 parents cd9fb4a + c166ca5 commit ef39d01
Show file tree
Hide file tree
Showing 5 changed files with 389 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"gogga": ">=3.1.1",
"jcli": "0.25.0-beta.3",
"niknaks": ">=0.9.8"
"niknaks": ">=0.17.0"
},
"description": "The official Tristan language compiler project",
"homepage": "http://deavmi.assigned.network/projects/tlang",
Expand Down
100 changes: 100 additions & 0 deletions source/tlang/compiler/symbols/containers.d
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import tlang.compiler.symbols.typing.core;

// AST manipulation interfaces
import tlang.compiler.symbols.mcro : MStatementSearchable, MStatementReplaceable, MCloneable;
import niknaks.arrays : insertAt;

/**
* Used so often that we may as well
Expand Down Expand Up @@ -204,6 +205,46 @@ public class Module : Entity, Container
}
}

public bool insertBefore(Statement thiz, Statement that)
{
// Direct replacement
for(size_t i = 0; i < this.statements.length; i++)
{
if(that == this.statements[i])
{
// Insert and re-parent
this.statements = insertAt(this.statements, i, thiz);
thiz.parentTo(this);
return true;
}
}

// Matching within
for(size_t i = 0; i < this.statements.length; i++)
{
MStatementReplaceable replaceable = cast(MStatementReplaceable)this.statements[i];
if(replaceable)
{
if(replaceable.insertBefore(thiz, that))
{
return true;
}
}
}

return false;
}

// public bool insertAfter(Statement thiz, Statement that)
// {

// }

// public bool remove(Statement thiz)
// {

// }

/**
* Provides a string representation of
* this module
Expand Down Expand Up @@ -321,6 +362,36 @@ public class Struct : Type, Container, MCloneable
}
}

public bool insertBefore(Statement thiz, Statement that)
{
// Direct replacement
for(size_t i = 0; i < this.statements.length; i++)
{
if(that == this.statements[i])
{
// Insert and re-parent
this.statements = insertAt(this.statements, i, thiz);
thiz.parentTo(this);
return true;
}
}

// Matching within
for(size_t i = 0; i < this.statements.length; i++)
{
MStatementReplaceable replaceable = cast(MStatementReplaceable)this.statements[i];
if(replaceable)
{
if(replaceable.insertBefore(thiz, that))
{
return true;
}
}
}

return false;
}

/**
* Clones this struct recursively returning a
* fresh copy of all its members and the struct
Expand Down Expand Up @@ -482,6 +553,35 @@ public class Clazz : Type, Container
}
}

public bool insertBefore(Statement thiz, Statement that)
{
// Direct replacement
for(size_t i = 0; i < this.statements.length; i++)
{
if(that == this.statements[i])
{
// Insert and re-parent
this.statements = insertAt(this.statements, i, thiz);
thiz.parentTo(this);
return true;
}
}

// Matching within
for(size_t i = 0; i < this.statements.length; i++)
{
MStatementReplaceable replaceable = cast(MStatementReplaceable)this.statements[i];
if(replaceable)
{
if(replaceable.insertBefore(thiz, that))
{
return true;
}
}
}

return false;
}
}


Expand Down
Loading

0 comments on commit ef39d01

Please sign in to comment.