- Joined
- Jun 21, 2012
- Messages
- 432
joining at the loop war >:3
JASS:while ((u = FirstOfGroup(g)) != null) // ... endwhile
orwhile (u = FirstOfGroup(g))
more ideas more ideas more ideas =)
joining at the loop war >:3
JASS:while ((u = FirstOfGroup(g)) != null) // ... endwhile
orwhile (u = FirstOfGroup(g))
repeat
// blah blah
until ( boolean )
or you can do such :
JASS:repeat // blah blah until ( boolean )
loop
exitwhen boolean
endloop
Question..
Can anyone that knows Java help me code this? It's really hard : (, lol
I was originally going to focus on doing vJASS, but I decided to save it for later since it's such a mess and just do what I call xJASS,
globals
private Table ta=Table.create()
endglobals
function xJassInitStructsGlobals takes nothing returns nothing
set ta=Table.create()
endfucntion
It would be very useful that could init structs in global declarations:
JASS:globals private Table ta=Table.create() endglobals
then when compiling the srcipt would have to be like this:
JASS:function xJassInitStructsGlobals takes nothing returns nothing set ta=Table.create() endfucntion
what do you say?
Classes to Review: 1 (to finalization)
Classes to Test: 4 (to final review)
Classes to Fix: 3 (to test)
Classes to Update: 8 (to fix/test)
Classes to Create: 1 (to fix/test)
Classes to Delete?: 1 (pending review)
Finalized Classes
Tested Classes
SymbolPrivilege (review documentation)
To Test
SymbolPrivilegeLocal
SymbolPrivilegeRegional
Review Classes
SymbolSignature (review before test)
Symbol (review before test)
SymbolGate (review before test)
SymbolPath (review before test)
Doing
SymbolPathSet (fix retain, remove, etc to use iterator)
SymbolPathSetHashMap (fix retain, remove, etc to use iterator)
SymbolPathSetLinkedList (fix retain, remove, etc to use iterator)
To Do
SymbolResolve -> SymbolLinkable (update)
- a symbol that can be linked to other symbols
SymbolBase -> SymbolRegional (update)
SymbolScope (update)
SymbolType (update)
SymbolVariable (each variable needs a set of paths that continue to become more strict)
(each path leads to the same place, but they all grant different privileges)
(normally, 3 paths, private/protected/public)
(what happens when a variable is typecast?)
(wrap the variable with another variable whose instance is the original variable, but it leads
somewhere else)
(Typecast extends Variable) (this doesn't seem right, but Typecast is almost identical to Variable)
additionalPrivileges under restrictPrivileges
restrictedPrivileges = intersect(providedPrivileges, union(additionalPrivileges, grantedPrivileges))
useful for typecasting (may be protected or private privileges depending on type being cast to)
add to SymbolGate
SymbolFunction (create)
SymbolSignatureFunction (update)
SymbolSignatureTypecast (update)
SymbolSignatureFunctionOrTypecast (update)
- first either resolve a function or resolve a type
- if resolved a type, then try to resolve typecast from type or fail
SymbolQuery (update)
SymbolBaseQuery -> SymbolQuery (include) (delete?)
Module Pattern (vJASS)
Inheritance Pattern
Generic Pattern with an Implementation
Function Overload Pattern
Typecast Pattern
Internal Pattern
Closure Pattern
Variable of same Type Pattern
Variable Parameter of same Type Pattern
Macro Pattern
Define Pattern (parallel tables)
package symboltable;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
/**
* A symbol privilege grants rights to access another symbol privilege. These rights are stored as
* a set of flags. Accessing a symbol privilege requires the flags of that symbol privilege. The flags
* provided are from the accessing symbol privilege.
* <p>
* A symbol privilege can intersect and union with collections. However, terminal nodes of these
* collections must be symbol privileges.
* <p>
* A symbol privilege can be used for things like access modifiers or requirements
* to go down a link in a virtual network. The default implementation dictates are
* that all requirements are met if the required set of flags are a subset of the
* provided set of flags.
*/
public class SymbolPrivilege implements Set<SymbolPrivilege>
{
public static final ImmutableSet<SymbolPrivilege> emptyMask = ImmutableSet.of();
public static final ImmutableMap<Class<? extends SymbolPrivilege>, ImmutableSet<SymbolPrivilege>> emptyMap = ImmutableMap.of();
public static final SymbolPrivilege emptyPrivilege =
new SymbolPrivilege(
emptyMap);
/**
* A map from this point on is a Map containing sets, which in turn contain privileges.
* A mask from this point on is a Set containing privileges.
* The map organizes the privileges by class. Without this organization, privileges
* would not be able to interact with each other without having both the same types
* of privileges and the same order.
*/
private final ImmutableMap<Class<? extends SymbolPrivilege>, ImmutableSet<SymbolPrivilege>> map;
public final boolean isComposite;
/**
* This constructor is used when defining a new privilege.
* This new privilege is used in composite privileges.
*/
public SymbolPrivilege()
{
map = ImmutableMap.of(getClass(), ImmutableSet.of(this));
isComposite = false;
} // SymbolPrivilege
/**
* This constructor is used by composite privileges.
*/
private SymbolPrivilege(ImmutableMap<Class<? extends SymbolPrivilege>, ImmutableSet<SymbolPrivilege>> map)
{
this.map = map;
isComposite = true;
} // SymbolPrivilege
/**
* This should be implemented by derived classes. This default implementation determines whether the provided
* privileges are accepted by the required privileges or not.
*
* @param requiredMask mask required for success
* @param providedMask mask provided
* @return provided mask was accepted by required mask
*/
protected boolean acceptsMask(ImmutableSet<SymbolPrivilege> requiredMask, ImmutableSet<SymbolPrivilege> providedMask)
{
// the base privilege requires that provided privileges has all required
// privileges
return providedMask.containsAll(requiredMask);
} // acceptsMask
/**
* This can't be a general implementation as how deep the collections go for a map and the organization of
* those collections in that map is unknown.
* <p>
* Does not add empty masks to the map.
*/
private static <S extends SymbolPrivilege> void addMap(Map<Class<? extends S>, HashSet<S>> map,
Map<Class<? extends S>, ? extends Collection<S>> mapToAdd)
{
HashSet<S> collection;
for (Entry<Class<? extends S>, ? extends Collection<S>> entry : mapToAdd.entrySet())
{
if (!entry.getValue().isEmpty())
{
collection = map.getOrDefault(entry.getKey(), null);
if (collection == null)
{
collection = new HashSet<S>();
map.put(entry.getKey(), collection);
} // if
collection.addAll(entry.getValue());
} // if
} // for
} // addMap
/**
* Convert array of collections to a map.
*/
private static HashMap<Class<? extends SymbolPrivilege>, HashSet<SymbolPrivilege>> toMap(Object... collections)
{
// this is the final map
HashMap<Class<? extends SymbolPrivilege>, HashSet<SymbolPrivilege>> map =
new HashMap<Class<? extends SymbolPrivilege>, HashSet<SymbolPrivilege>>();
// if the object is a privilege, add it to the above map
// if the object is some collection, convert it to a map and then add
// that to the above map
for (Object object : collections)
{
if (isClass(object))
{
addMap(map, ((SymbolPrivilege) object).map);
} // if
else if (Utils.isClass(Collection.class, object))
{
addMap(map, toMap(((Collection<?>) object).toArray()));
} // else if
} // for
return map;
} // toMap
/**
* This is used to directly intersect an array of collections together into a map. A HashSet
* is used rather than an ImmutableSet because it is more efficient than recreating
* the structure over and over again. This HashSet is the map of the intersection.
*/
private static Map<Class<? extends SymbolPrivilege>, HashSet<SymbolPrivilege>> intersectToMap(Object... collections)
{
Map<Class<? extends SymbolPrivilege>, HashSet<SymbolPrivilege>> map = toMap(collections);
// if the object is a privilege, retain that object's map
// if the object is a collection, retain the intersection of its
// elements
for (Object object : collections)
{
// intersection with empty set is still empty
if (map.isEmpty())
{
break;
} // if
if (isClass(object))
{
Utils.retainMap(map, ((SymbolPrivilege) object).map);
} // if
else if (Utils.isClass(Collection.class, object))
{
Utils.retainMap(map, intersectToMap(((Collection<?>) object).toArray()));
} // else if
else
{
map.clear();
} // else
} // for
return map;
} // intersectToMap
/**
* This compiles a map into a SymbolPrivilege. Each set is first converted into an immutable
* set. After this, the map is converted into an immutable map.
*/
private static SymbolPrivilege compileMap(Map<Class<? extends SymbolPrivilege>, HashSet<SymbolPrivilege>> map)
{
// the passed in map will contain no empty masks
if (map.isEmpty())
{
return emptyPrivilege;
} // if
// composite privileges must be greater than size 1
if (map.size() == 1)
{
Set<SymbolPrivilege> mask = map.values().iterator().next();
if (mask.size() == 1)
{
return mask.iterator().next();
} // if
} // if
// have to create a new map to specifically hold ImmutableSet
HashMap<Class<? extends SymbolPrivilege>, ImmutableSet<SymbolPrivilege>> transitionMap =
new HashMap<Class<? extends SymbolPrivilege>, ImmutableSet<SymbolPrivilege>>();
// add the old map to the new map, converting Set to ImmutableSet
for (Map.Entry<Class<? extends SymbolPrivilege>, HashSet<SymbolPrivilege>> entry : map.entrySet())
{
transitionMap.put(entry.getKey(), ImmutableSet.copyOf(entry.getValue()));
} // for
return new SymbolPrivilege(ImmutableMap.copyOf(transitionMap));
} // compileMap
/**
* @return intersection of collections
*/
public static SymbolPrivilege intersect(Object... collections)
{
return compileMap(intersectToMap(collections));
} // intersect
/**
* @return union of collections
*/
public static SymbolPrivilege union(Object... collections)
{
return compileMap(toMap(collections));
} // union
public static boolean isClass(Object object)
{
return Utils.isClass(SymbolPrivilege.class, object);
} // isClass
/**
* This will return true if the provided privileges are accepted by this
* privilege.
*
* @param this required privileges
* @param providedPrivileges provided privileges
* @return provided privileges accepted?
*/
public boolean accepts(SymbolPrivilege providedPrivileges)
{
if (providedPrivileges == null)
{
providedPrivileges = emptyPrivilege;
} // if
ImmutableSet<SymbolPrivilege> providedMask;
ImmutableSet<SymbolPrivilege> requiredMask;
SymbolPrivilege derivedClass;
// all masks must be accepted
for (Map.Entry<Class<? extends SymbolPrivilege>, ImmutableSet<SymbolPrivilege>> entry : this.map.entrySet())
{
providedMask = providedPrivileges.map.getOrDefault(entry.getKey(), emptyMask);
requiredMask = entry.getValue();
// the "acceptsMask" method is within a derived class
// this will always be safe because compileMap excludes all empty
// masks
derivedClass = requiredMask.iterator().next();
if (!derivedClass.acceptsMask(requiredMask, providedMask))
{
return false;
} // if
} // for
// if all masks were accepted, then the privileges are accepted
return true;
} // accepts
/**
* This will always return false for the empty set and composite sets. containsAll is more
* flexible.
*/
@Override
public boolean contains(Object object)
{
if (isEmpty() && (this == object || object == null))
{
return true;
} // if
if (isClass(object))
{
return map.getOrDefault(object.getClass(), emptyMask).contains(object);
} // if
return false;
} // contains
/**
* contains all for composite, composite
*/
private boolean compositeComposite(SymbolPrivilege privilege)
{
for (Map.Entry<Class<? extends SymbolPrivilege>, ImmutableSet<SymbolPrivilege>> entry : privilege.map.entrySet())
{
if (!map.getOrDefault(entry.getKey(), emptyMask).containsAll(entry.getValue()))
{
return false;
} // if
} // for
return true;
} // compositeComposite
/**
* contains all for defined, composite
*/
private boolean definedComposite(SymbolPrivilege privilege)
{
return privilege.isEmpty() || map.getOrDefault(privilege.getClass(), emptyMask).contains(privilege);
} // definedComposite
/**
* contains all for composite, defined
*/
private boolean compositeDefined(SymbolPrivilege privilege)
{
return map.getOrDefault(privilege.getClass(), emptyMask).contains(privilege);
} // compositeDefined
/**
* contains all for defined, defined
*/
private boolean definedDefined(SymbolPrivilege privilege)
{
return this == privilege;
} // compositeDefined
private boolean containsAllPrivilege(SymbolPrivilege privilege)
{
if (isComposite)
{
if (privilege.isComposite)
{
return compositeComposite(privilege);
} // if
else
{
return compositeDefined(privilege);
} // else
} // if
else if (privilege.isComposite)
{
return definedComposite(privilege);
} // else if
else
{
return definedDefined(privilege);
} // else
} // containsAllPrivilege
@Override
public boolean containsAll(Collection<?> collection)
{
if (collection != null)
{
if (isClass(collection))
{
if (!containsAllPrivilege((SymbolPrivilege) collection))
{
return false;
} // if
} // if
else
{
for (Object object : collection)
{
if (object != null)
{
if (Utils.isClass(Collection.class, object))
{
if (isClass(object))
{
if (!containsAllPrivilege((SymbolPrivilege) object))
{
return false;
} // if
} // if
else if (!containsAll((Collection<?>) object))
{
return false;
} // else
} // if
else
{
return false;
} // else
} // if
} // for
} // else
} // if
return true;
} // containsAll
@Override
public boolean equals(Object object)
{
return (this == object || (isEmpty() && object == null))
|| (isClass(object) && ((SymbolPrivilege) object).size() == size() && containsAllPrivilege((SymbolPrivilege) object));
} // equals
/**
* @return map empty?
*/
@Override
public boolean isEmpty()
{
return this == emptyPrivilege;
} // isEmpty
/**
* @return privilege count
*/
@Override
public int size()
{
int length = 0;
for (ImmutableSet<SymbolPrivilege> mask : map.values())
{
length += mask.size();
} // for
return length;
} // size
/**
* @return map to set
*/
private Set<SymbolPrivilege> toSet()
{
ImmutableSet.Builder<SymbolPrivilege> builder = ImmutableSet.builder();
for (Set<SymbolPrivilege> mask : map.values())
{
builder.addAll(mask);
} // for
return builder.build();
} // toSet
/**
* @return map iterator
*/
@Override
public Iterator<SymbolPrivilege> iterator()
{
return toSet().iterator();
} // iterator
/**
* @return map to array
*/
@Override
public Object[] toArray()
{
return toSet().toArray();
} // toArray
/**
* @return map to array
*/
@Override
public <T> T[] toArray(T[] a)
{
return toSet().toArray(a);
} // toArray
/**
* Not supported.
*/
@Override
public boolean add(SymbolPrivilege e)
{
throw new UnsupportedOperationException();
} // add
/**
* Not supported.
*/
@Override
public boolean remove(Object o)
{
throw new UnsupportedOperationException();
} // remove
/**
* Not supported.
*/
@Override
public boolean addAll(Collection<? extends SymbolPrivilege> c)
{
throw new UnsupportedOperationException();
} // addAll
/**
* Not supported.
*/
@Override
public boolean removeAll(Collection<?> c)
{
throw new UnsupportedOperationException();
} // removeAll
/**
* Not supported.
*/
@Override
public boolean retainAll(Collection<?> c)
{
throw new UnsupportedOperationException();
} // retainAll
/**
* Not supported.
*/
@Override
public void clear()
{
throw new UnsupportedOperationException();
} // clear
} // SymbolPrivilege
I'm talking to you Ruke >: o
struct S1 extends array
public integer b
endstruct
struct S2 extends array
public method operator delegate a takes nothing returns S1
return this
endmethod
public method operator typecast b takes unit u returns thistype
return GetUnitUserData(u)
endmethod
endstruct
struct S3<T>
private T data
public method store takes T value returns nothing
set data = value
endmethod
endstruct
// see how T is passed in, but it could be a type or anything too
struct S4<T, T2> extends S3<T>
endstruct
// when wanting a specific macro implementation for array space
struct S5 extends S3<unit>
endstruct
function Test takes nothing returns nothing
local S2 s2 = 0
local unit u = ...
// when wanting to go off of a shared macro implementation
local S4<unit, unit> s4 = S4<unit, unit>.create()
set s2.b = 5 // S1(0).b = 5
set S2(u).b = 5 // S1(GetUnitUserData(u)).b = 5
call s4.store(u)
endfunction
// idea to use existing allocators with overload, but drop the polymorphism in inheritance
static struct M
endstruct
// idea for one-time code execution
integer h = 5
set h = 6
local unit u = ...
set u.life = 60 // how will this be supported?
// generics for modules
module S<T>
public method boo takes T t returns nothing
endmethod
endmodule
struct M
implement S<unit>
// masking module members like with delegates
public method boo takes unit t returns nothing
call Module.S.boo(t)
endmethod
// function overloading
public method boo takes integer t returns nothing
endmethod
endstruct
function M takes nothing returns nothing
local integer i // var 1
if (true) then
local integer i // masks i, var 2
endif
if (true) then
local integer i // masks 2, var 2 again, not a third local var!
endif
endfunction
method operator [][][] takes integer i, integer i2, integer i3 returns integer
endmethod
integer m = thistype[1][2][3] // use the above
// generics for modules
module S<T>
public method boo takes T t returns nothing
endmethod
endmodule
struct M
implement S<unit>
implement S<widget>
// masking module members like with delegates
public method boo takes unit t returns nothing
call Module.S.boo(t) //@ambiguous@
endmethod
// function overloading
public method boo takes integer t returns nothing
endmethod
endstruct
package org.gradle;
import java.util.Arrays;
public class Symbol<T extends Enum<T>> {
private final ResolutionPhase<T>[] phases;
private final Signature signature;
private final Privilege requiredPrivileges;
@SafeVarargs
public Symbol(Privilege requiredPrivileges, Signature signature,
ResolutionPhase<T>... phases) {
this.requiredPrivileges = requiredPrivileges;
this.signature = signature;
this.phases = phases;
}
@Override
public boolean equals(Object object) {
return object != null && object instanceof Symbol
&& signature.equals(((Symbol<?>) object).signature);
}
public Symbol<T> getClosestSymbol(Privilege providedPrivileges,
Signature signature) {
Symbol<T> closestMatch = null;
int closestDistance = Signature.INFINITY;
int currentDistance = 0;
for (ResolutionPhase<T> phase : phases) {
for (Symbol<T> symbol : phase.getSymbols(providedPrivileges,
signature)) {
currentDistance = signature.distance(symbol.getSignature());
if (currentDistance < closestDistance) {
if (currentDistance == 0) {
return symbol;
}
closestMatch = symbol;
closestDistance = currentDistance;
}
}
}
return closestMatch;
}
public Privilege getRequiredPrivileges() {
return requiredPrivileges;
}
public ResolutionPhase<T>[] getResolutionPhases() {
return phases;
}
public ResolutionPhase<T>[] getResolutionPhases(
@SuppressWarnings("unchecked") T... phaseTypes) {
Arrays.sort(phaseTypes);
@SuppressWarnings("unchecked")
ResolutionPhase<T>[] phases = new ResolutionPhase[phaseTypes.length];
for (int i = 0; i < phases.length; ++i) {
phases[i] = this.phases[phaseTypes[i].ordinal()];
}
return phases;
}
public Signature getSignature() {
return signature;
}
@Override
public int hashCode() {
return signature.hashCode();
}
}