} else {
switch(_role) {
case DECLARE:
{
consumeSymbol();
FunctionStatement function = _statement.getFunctionStatement();
type = function.lookupDeclaration(symbol);
if (type == null) {
type = function.declare(symbol);
}
}
break;
case ASSIGN:
{
consumeSymbol();
type = _statement.lookupAnyDeclaration(symbol);
if (type == null) {
consumeSymbol();
FunctionStatement function = _statement.getFunctionStatement();
if (function != null) {
type = function.declare(symbol);
} else {
listener.error(_location, "Entity '" + _name + "' is undeclared");
return null;
}
}
}
break;
default:
{
type = _statement.lookupAnyDeclaration(symbol);
if (type == null) {
type = LangModule.__module__.lookupDeclaration(symbol);
if (type == null) {
consumeSymbol();
type = lookupLibrary(listener);
if (type == null) {
listener.error(_location, "Entity '" + _name + "' is undeclared");
return null;
}
symbol = type.getName();
} else {
type = LangModule.__module__;
symbol = type.getName();
}
} else {
consumeSymbol();
}
}
break;
}
}
type = followImports(listener, type);
if (type == null) {
return null;
}
if (type instanceof ReflectedJava) {
if (type instanceof Reflection) {
return new JavaClassNode(type.getName());
} else {
return new JavaClassNode(type.getParent().getName());
}
}
switch(type.getType()) {
case Type.MODULE:
case Type.NAMESPACE:
{
if (!hasMoreSymbols()) {
return new TypeNode(type);
}
return construct(listener, (Scope)type);
}
case Type.INTERFACE:
case Type.CLASS:
{
return classConstruct(listener, (Scope)type);
}
case Type.GLOBAL_NAMESPACE:
{
return GlobalNamespaceNode.INSTANCE;
}
case Type.SYSTEM_NAMESPACE:
{
return new NamespaceNode((NamespaceType)type);
}
case Type.FUNCTION:
{
return onFunction(listener, type);
}
case Type.INTERFACE_METHOD:
{
return new TypeNode(type);
}
case Type.METHOD:
{
MethodType method = (MethodType)type;
ClassStatement context = _statement.getClassStatement();
if (type instanceof FunctionStatement) {
FunctionStatement function = (FunctionStatement)type;
if (function.getContext() != null) {
if (hasArgs()) {
return new InlinedCallNode(_statement.getFunctionStatement(), function, consumeArgs());
} else {
return new InlinedFunctionNode(_statement.getFunctionStatement(), function);
}
}
}
if (hasMoreSymbols()) {
return new TypeNode(type);
} else {
Grammar.checkInstanceAmbiguity(listener, _location, context, method);
if (hasArgs()) {
//methodname(...)
checkArguments(listener, method);
return new StaticInvokeNode(method.getClassType(), context, method, consumeArgs());
} else {
//methodname
return new DelegateNode(new ThisNode(context, method.getClassType()), method);
}
}
}
case Type.CONSTRUCTOR:
{
if (!hasMoreSymbols()) {
if (hasArgs()) {
listener.error(_location, "Trying to call constructor '"+type+"'");
return null;
}
}
return new TypeNode(type);
}
case Type.CONSTANT_VARIABLE:
{
if (_role != GET) {
listener.error(_location, "Attempting to assign to constant '"+symbol+"'");
}
return new ConstantVariableNode((ConstantVariableType)type);
}
case Type.STATIC_VARIABLE:
{
return new StaticVariableNode((StaticVariableType)type);
}
case Type.MEMBER_VARIABLE:
{
ClassStatement context = _statement.getClassStatement();
MemberVariableType member = (MemberVariableType)type;
Grammar.checkInstanceAmbiguity(listener, _location, context, member);
return new MemberVariableNode(context, member);
}
case Type.FUNCTION_PARAMETER:
case Type.LOCAL_VARIABLE:
{
FunctionStatement context = _statement.getFunctionStatement();
if (type.getParent() != context) {
return new EscapedVariableNode(symbol, (LocalVariableStatement)type, context);
} else {
return new VariableNode((LocalVariableStatement)type);
}