Created
April 8, 2013 06:14
-
-
Save ecere/5334606 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Type ProcessType(OldList specs, Declarator decl) | |
{ | |
return _ProcessType(specs, decl, null); | |
} | |
public Type _ProcessType(OldList specs, Declarator decl, Type parentType) | |
{ | |
Type type = parentType; | |
Declarator subDecl = decl ? decl.declarator : null; | |
if(!parentType) | |
type = ProcessTypeSpecs(specs, decl == null); | |
if(decl) | |
{ | |
switch(decl.type) | |
{ | |
case extendedDeclarator: | |
case extendedDeclaratorEnd: | |
case bracketsDeclarator: | |
case structDeclarator: | |
break; | |
case functionDeclarator: | |
{ | |
type = { refCount = 1, kind = functionType, returnType = type }; | |
if(decl.function.parameters) | |
{ | |
TypeName param; | |
for(param = decl.function.parameters->first; param; param = param.next) | |
type.params.Add(ProcessType(param.qualifiers, param.declarator)); | |
} | |
break; | |
} | |
case arrayDeclarator: | |
{ | |
type = { refCount = 1, kind = arrayType, arraySizeExp = CopyExpression(decl.array.exp), freeExp = true, type = type }; | |
if(decl.array.enumClass) | |
type.enumClass = decl.array.enumClass.symbol; | |
break; | |
} | |
case pointerDeclarator: | |
{ | |
Pointer pointer = decl.pointer.pointer; | |
while(pointer) | |
{ | |
OldList * qualifiers = pointer.qualifiers; | |
type = { refCount = 1, kind = pointerType, type = type }; | |
if(qualifiers) | |
{ | |
Specifier spec; | |
for(spec = qualifiers->first; spec; spec = spec.next) | |
{ | |
if(spec.type == baseSpecifier && spec.specifier == CONST) | |
type.constant = true; | |
} | |
} | |
pointer = pointer.pointer; | |
} | |
break; | |
} | |
case identifierDeclarator: | |
{ | |
Identifier id = decl.identifier; | |
type.name = CopyString(id.string); | |
break; | |
} | |
default: | |
PrintLn("Unhandled Declarator Type: ", decl.type); | |
} | |
} | |
if(subDecl) | |
type = _ProcessType(null, subDecl, type); | |
return type; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment